# Elementary Functions

The Math class in the .NET framework Base Class Libraries implements a large number of elementary functions. Unfortunately, this list is far from complete. The Elementary class in the Extreme.Mathematics namespace defines many elementary functions that are missing from Math class.

## Utility Functions

Some functions exist in the .NET Framework, but there implementation is far from optimal. We've implemented them in a more efficient way that in some cases is up to 50x faster.

Method | Description |
---|---|

Checks if a value is Not-a-Number. | |

Checks if a value represents a finite real number. | |

Checks if a value represents positive or negative infinity. | |

Restricts a value to the specified interval. | |

Returns the Heaviside step function. |

## Trigonometric Functions

Calculating a trigonometric function for an argument close to a multiple of π/2 is often problematic. Fortunately, in the actual expressions, the argument is often expressed as a multiple of π. In these cases, it is possible to compute the exact values of the sine, cosine, and tangent. The following methods implement this functionality:

Method | Description |
---|---|

Accurately computes the cosine of a value times π. | |

Accurately computes the sine of a value times π. | |

Accurately computes the tangent of a value times π. | |

Returns the unnormalized Sinc function. |

A related problem is that the standard methods quickly become less accurate for larger arguments. To make the calculation of a trigonometric function fast and accurate, the argument must be reduced to a relatively small interval around zero. This is done by subtracting an integer multiple of π from the argument. The standard implementation uses a value of π with only 66 bits of precision. Some precision is lost for arguments as small as 30,000.

Worse still, for arguments greater than or equal to *2^63*, the argument is returned unchanged.
Aside from the fact that this result is completely meaningless, it can cause problems in code that relies
on the fact that the sine and cosine are bounded by *-1* and *+1*.

The trigonometric methods Sin, Cos, and Tan perform complete argument reduction, and return accurate results even for very large arguments.

Method | Description |
---|---|

Accurately computes the cosine of a value. | |

Accurately computes the sine of a value. | |

Accurately computes the tangent of a value. |

## Hyperbolic Functions

Method | Description |
---|---|

Hyperbolic cosine. | |

Hyperbolic cotangent. | |

Hyperbolic co-secant. | |

Hyperbolic sine. | |

Hyperbolic secant. | |

Hyperbolic tangent. |

## Inverse Hyperbolic Functions

Method | Description |
---|---|

Inverse hyperbolic cosine. | |

Inverse hyperbolic cotangent. | |

Inverse hyperbolic co-secant. | |

Inverse hyperbolic secant. | |

Inverse hyperbolic sine. | |

Inverse hyperbolic tangent. |

## Exponential, Logarithmic and Miscellaneous Functions

The functions in this section calculate expressions with a higher accuracy than using the standard expression would produce.

Method | Description |
---|---|

The exponential function minus one, x
is near zero.
| |

The hypotenuse of a right-angled triangle with specified sides. | |

Lambert's | |

The natural logarithm of | |

A number raised to an integer power. | |

The difference between the square root of a number close to 1 and 1. |

The Pow method is useful only for larger values of the exponent. For small values, the JIT compiler automatically converts the expression to an optimized multiplication.

## Elementary Functions of Decimal Values

The Decimal type is a decimal floating-point type with up to 28 digits of precision. Transcendental functions like sine, cosine, exponential and logarithm are not available in the Math class. The DecimalMath class implements all the methods that are defined for Double for the decimal type to full precision. Because the implementation is mostly in software, the evaluation of these functions takes significantly longer than the built-in functions for double-precision numbers.

Method | Description |
---|---|

Inverse cosine. | |

Inverse sine. | |

Inverse tangent. | |

Inverse tangent with two arguments. | |

Cosine. | |

Hyperbolic cosine. | |

Exponential function. | |

Natural logarithm. | |

Logarithm with specified base. | |

Base 10 logarithm. | |

Sine. | |

Hyperbolic sine. | |

Square root. | |

Tangent. | |

Hyperbolic tangent. |