## Elementary Functions | Extreme Optimization Numerical Libraries for .NET Professional |

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.

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. |

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. |

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

Hyperbolic cosine. | |

Hyperbolic cotangent. | |

Hyperbolic co-secant. | |

Hyperbolic sine. | |

Hyperbolic secant. | |

Hyperbolic tangent. |

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

Inverse hyperbolic cosine. | |

Inverse hyperbolic cotangent. | |

Inverse hyperbolic co-secant. | |

Inverse hyperbolic secant. | |

Inverse hyperbolic sine. | |

Inverse hyperbolic tangent. |

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, e | |

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

Lambert's W function, the (real) solution W of
x = We | |

The natural logarithm of 1+x calculated to high precision for x close to zero. | |

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.

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. |

Copyright © 2004-2021,
Extreme Optimization. All rights reserved.

*Extreme Optimization,* *Complexity made simple*, *M#*, and *M
Sharp* are trademarks of ExoAnalytics Inc.

*Microsoft*, *Visual C#, Visual Basic, Visual Studio*, *Visual
Studio.NET*, and the *Optimized for Visual Studio* logo

are
registered trademarks of Microsoft Corporation.