# MathLib.Functn()

Unlike all other MathLib constructors `MathLib.Functn`

is called without the `new`

keyword, due to technical limitations in JavaScript. Most of the times however you probably don't need to call `MathLib.Functn`

directly, since MathLib has very many predefined functions.

## Examples

Lets say we want to implement the Fermi rounding, which is used in Fermi estimates: $$\mathrm{Fermi}(x)={10}^{\mathrm{round}({\mathrm{log}}_{10}x)}$$ First we have to create the JavaScript function like this:```
var fermi = function (x) {
return Math.pow(10, Math.round(Math.log(x) / Math.LN10))
}
```

Next we decide what our bound variable should be. Lets choose `x`

like in the formula above.
```
var args = [MathLib.Expression.variable('x')];
```

Since MathLib also works with functions that have more then one variable we have to put the variable in an array.
Now we can generate the mathematical expression which is describing the function. This is important when modifying the function later.
```
var expr = new MathLib.Expression({
subtype: 'functionDefinition',
args: args,
content: [new MathLib.Expression({
subtype: 'functionCall',
content: args,
value: 'Fermi'
})
]
})
```

Finally we can construct the Functn:
```
MathLib.Functn(fermi, {
name: 'Fermi',
expression: expr
});
```

## Properties

- .constructor
- The function
`MathLib.Functn` - .type
- The string "functn"

## Methods

- .diff()
- Numeric derivative at a given point.
- .quad()
- Numeric evaluation of an integral.
- .toContentMathML()
- Returns a content MathML representation of the function as string.
- .toLaTeX()
- Returns a LaTeX representation of the function as string.
- .toMathML()
- Returns a presentation MathML representation of the function as string.
- .toString()
- Returns a representation of the function as string.

## Links

- Function (mathematics) on Wikipedia