Additional mathematical routines.

This document describes the math unit. The math unit was initially written by Florian Klaempfl. It provides mathematical functions which aren't covered by the system unit.

This chapter starts out with a definition of all types and constants that are defined, after which an overview is presented of the available functions, grouped by category, and the last part contains a complete explanation of each function.

The following things must be taken into account when using this unit:

1. This unit is compiled in Object Pascal mode so all integers are 32 bit.
2. Some overloaded functions exist for data arrays of integers and floats. When using the address operator (@) to pass an array of data to such a function, make sure the address is typecasted to the right type, or turn on the 'typed address operator' feature. failing to do so, will cause the compiler not be able to decide which function you want to call.

Min/max determination

Functions to determine the minimum or maximum of numbers:

| Name | Description
| Maximum of 2 values
| Maximum of an array of integer values
| Maximum of an array of values
| Minimum of 2 values
| Minimum of an array of integer values
| Minimum of an array of values

Angle unit conversion

Routines to convert angles between different angle units.

| Name | Description
| convert cycles to radians
| convert degrees to grads
| convert degrees to radians
| convert grads to degrees
| convert grads to radians
| convert radians to cycles
| convert radians to degrees
| convert radians to grads

Trigoniometric functions

| Name | Description
| calculate reverse cosine
| calculate reverse sine
| calculate reverse tangent
| calculate cotangent
| calculate sine and cosine
| calculate tangent

Hyperbolic functions

| Name | Description
| caculate reverse hyperbolic cosine
| caculate reverse hyperbolic sine
| caculate reverse hyperbolic tangent
| calculate hyperbolic cosine
| calculate hyperbolic sine
| calculate hyperbolic tangent

Exponential and logarithmic functions

| Name | Description
| Raise float to integer power
| Calculate $2^p x$
| calculate log(x+1)
| calculate 10-base log
| calculate 2-base log
| calculate N-base log
| raise float to arbitrary power

Number converting

| Name | Description
| Round to infinity
| Round to minus infinity
| Return mantissa and exponent

Statistical functions

| Name | Description
| Mean of values
| Mean and standard deviation of values
| Moments, skew and kurtosis
| Population standarddeviation
| Population variance
| Gaussian distributed randum value
| Standard deviation
| Sum of values
| Sum of squared values
| Sum of values and squared values
| Total variance of values
| variance of values

Geometrical functions

| Name | Description
| Hypotenuse of triangle
| Euclidian norm

Float type used in all calls
All calculations are done with the Float type. This allows to recompile the unit with a different float type to obtain a desired precision. The pointer type is used in functions that accept an array of values of arbitrary length.
Pointer to type.
Type used in financial (interest) calculations.
End of period.
Start of period.
Exception raised when invalid arguments are passed to a function.
Arccos
returns the inverse cosine of its argument x. The argument x should lie between -1 and 1 (borders included).
If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
Arcosh
returns the inverse hyperbolic cosine of its argument x. The argument x should be larger than 1.

The arccosh variant of this function is supplied for Delphi compatibility.
If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
,
Arcsin
returns the inverse sine of its argument x. The argument x should lie between -1 and 1.
If the argument x is not in the allowed range, an EInvalidArgument exception is raised.
arctan2
calculates arctan(y/x), and returns an angle in the correct quadrant. The returned angle will be in the range $-\pi$ to $\pi$ radians. The values of x and y must be between -2\^{}64 and 2\^{}64, moreover x should be different from zero.

On Intel systems this function is implemented with the native intel fpatan instruction.
If x is zero, an overflow error will occur.
arsinh
returns the inverse hyperbolic sine of its argument x.

The arscsinh variant of this function is supplied for Delphi compatibility.
None.
artanh
returns the inverse hyperbolic tangent of its argument x, where x should lie in the interval [-1,1], borders included.

The arctanh variant of this function is supplied for Delphi compatibility.
In case x is not in the interval [-1,1], an EInvalidArgument exception is raised.
Ceil
returns the lowest integer number greater than or equal to x. The absolute value of x should be less than maxint.
If the asolute value of x is larger than maxint, an overflow error will occur.
Cosh
returns the hyperbolic cosine of it's argument {x}.
None.
Cotan
returns the cotangent of it's argument x. x should be different from zero.
If x is zero then a overflow error will occur.
Cycletorad
transforms it's argument cycle (an angle expressed in cycles) to radians. (1 cycle is $2 \pi$ radians).
None.
,
Degtograd
transforms it's argument deg (an angle in degrees) to grads.

(90 degrees is 100 grad.)
None.
,
Degtorad
converts it's argument deg (an angle in degrees) to radians.

(pi radians is 180 degrees)
None.
,
Floor
returns the largest integer smaller than or equal to x. The absolute value of x should be less than maxint.
If x is larger than maxint, an overflow will occur.
Frexp
returns the mantissa and exponent of it's argument x in mantissa and exponent.
None
Gradtodeg
converts its argument grad (an angle in grads) to degrees.

(100 grad is 90 degrees)
None.
,
Gradtorad
converts its argument grad (an angle in grads) to radians.

(200 grad is pi degrees).
None.
,
Hypot
returns the hypotenuse of the triangle where the sides adjacent to the square angle have lengths x and y.

The function uses Pythagoras' rule for this.
None.
Intpower
returns base to the power exponent, where exponent is an integer value.
If base is zero and the exponent is negative, then an overflow error will occur.
Ldexp
returns $2^p x$.
None.
Lnxp1
returns the natural logarithm of 1+X. The result is more precise for small values of x. x should be larger than -1.
If $x\leq -1$ then an EInvalidArgument exception will be raised.
Log10
returns the 10-base logarithm of X.
If x is less than or equal to 0 an 'invalid fpu operation' error will occur.
Log2
returns the 2-base logarithm of X.
If x is less than or equal to 0 an 'invalid fpu operation' error will occur.
Logn
returns the n-base logarithm of X.
If x is less than or equal to 0 an 'invalid fpu operation' error will occur.
Max
returns the maximum of Int1 and Int2.
None.
MaxIntValue
returns the largest integer out of the Data array.

This function is provided for Delphi compatibility, use the function instead.
None.
Maxvalue
returns the largest value in the data array with integer or float values. The return value has the same type as the elements of the array.

The third and fourth forms accept a pointer to an array of N integer or float values.
None.
Mean
returns the average value of data.

The second form accepts a pointer to an array of N values.
None.
meanandstddev
calculates the mean and standard deviation of data and returns the result in mean and stddev, respectively. Stddev is zero if there is only one value.

The second form accepts a pointer to an array of N values.
None.
min
returns the smallest value of Int1 and Int2;
None.
MinIntvalue
returns the smallest value in the Data array.

This function is provided for Delphi compatibility, use minvalue instead.
None
Minvalue
returns the smallest value in the data array with integer or float values. The return value has the same type as the elements of the array.

The third and fourth forms accept a pointer to an array of N integer or float values.
None.
momentskewkurtosis
calculates the 4 first moments of the distribution of valuesin data and returns them in m1,m2,m3 and m4, as well as the skew and kurtosis.
None.
Norm
calculates the Euclidian norm of the array of data. This equals sqrt(sumofsquares(data)).

The second form accepts a pointer to an array of N values.
None.
Popnstddev
returns the square root of the population variance of the values in the Data array. It returns zero if there is only one value.

The second form of this function accepts a pointer to an array of N values.
None.
,
Popnvariance
returns the square root of the population variance of the values in the Data array. It returns zero if there is only one value.

The second form of this function accepts a pointer to an array of N values.
None.
,
power
raises base to the power power. This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
None.
Radtocycle
converts its argument rad (an angle expressed in radians) to an angle in cycles.

(1 cycle equals 2 pi radians)
None.
,
Radtodeg
converts its argument rad (an angle expressed in radians) to an angle in degrees.

(180 degrees equals pi radians)
None.
,
Radtodeg
converts its argument rad (an angle expressed in radians) to an angle in grads.

(200 grads equals pi radians)
None.
,
randg
returns a random number which - when produced in large quantities - has a Gaussian distribution with mean mean and standarddeviation stddev.
None.
Sincos
calculates the sine and cosine of the angle theta, and returns the result in sinus and cosinus.

On Intel hardware, This calculation will be faster than making 2 calls to clculatet he sine and cosine separately.
None.
.
Sinh
returns the hyperbolic sine of its argument x.
Stddev
returns the standard deviation of the values in Data. It returns zero if there is only one value.

The second form of the function accepts a pointer to an array of N values.
None.
Sum
returns the sum of the values in the data array.

The second form of the function accepts a pointer to an array of N values.
None.
,
Sumofsquares
returns the sum of the squares of the values in the data array.

The second form of the function accepts a pointer to an array of N values.
None.
,
sumsandsquares
calculates the sum of the values and the sum of the squares of the values in the data array and returns the results in sum and sumofsquares.

The second form of the function accepts a pointer to an array of N values.
None.
,
Tan
returns the tangent of x.
If x (normalized) is pi/2 or 3pi/2 then an overflow will occur.
Tanh
returns the hyperbolic tangent of x.
None.
TotalVariance
returns the total variance of the values in the data array. It returns zero if there is only one value.

The second form of the function accepts a pointer to an array of N values.
None.
Variance
returns the variance of the values in the data array. It returns zero if there is only one value.

The second form of the function accepts a pointer to an array of N values.
None.