# Difference between revisions of "Modules/Math"

Jump to navigation
Jump to search

Line 59: | Line 59: | ||

{{SourceOakwood}} | {{SourceOakwood}} | ||

+ | [[Category:Modules]] |

## Latest revision as of 13:54, 24 February 2016

**Deutsch (de)** |
**English (en)** |
**հայերեն (hy)**

# Module Math and MathL

The module Math provides a basic set of general purpose functions using REAL arithmetic. The module MathL provides the same functions for LONGREAL arithmetic.

## Interface

```
DEFINITION Math;
CONST
pi = 3.14159265358979323846;
e = 2.71828182845904523536;
PROCEDURE sqrt (x : REAL) : REAL;
PROCEDURE power (x,base : REAL) : REAL;
PROCEDURE exp (x : REAL): REAL;
PROCEDURE ln (x : REAL) : REAL;
PROCEDURE log (x,base : REAL) : REAL;
PROCEDURE round (x : REAL) : REAL;
PROCEDURE sin (x : REAL) : REAL;
PROCEDURE cos (x : REAL) : REAL
PROCEDURE tan (x : REAL) : REAL;
PROCEDURE arcsin (x : REAL) : REAL;
PROCEDURE arccos (x : REAL) : REAL;
PROCEDURE arctan (x : REAL) : REAL;
PROCEDURE arctan2(x,y : REAL): REAL
PROCEDURE sinh (x:REAL):REAL;
PROCEDURE cosh (x:REAL):REAL;
PROCEDURE tanh (x:REAL):REAL;
PROCEDURE arcsinh(x:REAL):REAL;
PROCEDURE arccosh(x:REAL):REAL;
PROCEDURE arctanh(x:REAL):REAL;
END Math.
```

### Operations

- sqrt (x) returns the square root of x, where x must be positive
- sin, cos, tan (x) returns the sine, cosine or tangent value of x, where x is in radians
- arcsin, arcos, arctan (x) returns the arcsine, arcos, arctan value in radians of x, where x is in the sine, cosine or tangent value
- power(x, base) returns the x to the power base
- round(x) if fraction part of x is in range 0.0 to 0.5 then the result is the largest integer not greater than x, otherwise the result is x rounded up to the next highest whole number. Note that integer values cannot always be exactly represented in REAL or LONGREAL format.

- ln(x) returns the natural logarithm (base e) of x
- exp(x) is the exponential of x base e. x must not be so small that this exponential underflows nor so large that it overflows.
- log(x,base) is the logarithm of x base b. All positive arguments are allowed. The base b must be positive.
- arctan2(xn,xd) is the quadrant-correct arc tangent atan(xn/xd). If the denominator xd is zero, then the numerator xn must not be zero. All arguments are legal except xn = xd = 0.
- sinh(x) is the hyperbolic sine of x. The argument x must not be so large that exp(|x|) overflows.
- cosh(x) is the hyperbolic cosine of x. The argument x must not be so large that exp(|x|) overflows.
- tanh(x) is the hyperbolic tangent of x. All arguments are legal.
- arcsinh(x) is the arc hyperbolic sine of x. All arguments are legal.
- arccosh(x) is the arc hyperbolic cosine of x. All arguments greater than or equal to 1 are legal.
- arctanh(x) is the arc hyperbolic tangent of x.

|x| < 1 - sqrt(em), where em is machine epsilon.

Note that |x| must not be so close to 1 that the result is less accurate than half precision.

## Source

Based on the original ETH Math module, with additions from BK and Al Freed, NASA.

This article was created by using Oakwood Guidelines as a source.