Mathematical Functions

TwinCAT has its own mathematical functions implemented, because the math.h implementation provided by Microsoft is not real-time capable.
These functions are declared in TcMath.h, which is part of TwinCAT SDK. For x64 the operations are executed via SSE; on x86 systems the FPU is used.

Mathematical Functions 1:

TwinCAT 3.1 4018 or earlier

TwinCAT 3.1 4018 provides an fpu87.h with the same methods. This continues to exist and redirects to TcMath.h.

Mathematical Functions 2: Methods provided

Name

Description

sqr_

Calculates the square.

sqrt_

Calculates the square root.

sin_

Calculates the sine.

cos_

Calculates the cosine.

tan_

Calculates the tangent.

atan_

Calculates the angle whose tangent is the specified value.

atan2_

Calculates the angle whose tangent is the quotient of two specified values.

asin_

Calculates the angle whose sine is the specified value.

acos_

Calculates the angle whose cosine is the specified value.

exp_

Calculates e to the specified power.

log_

Calculates the logarithm of a specified value.

log10_

Calculates the base 10 logarithm of a specified value.

fabs_

Calculates the absolute value.

fmod_

Calculates the remainder.

ceil_

Calculates the smallest integer that is greater than or equal to the specified number.

floor_

Calculates the largest integer that is smaller than or equal to the specified number.

pow_

Calculates a specified number to the specified power.

sincos_

Calculates the sine and cosine of x.

fmodabs_

Calculates the absolute value that meets the Euclidean definition of the mod operation.

round_

Calculates a value and rounds to the nearest integer.

round_digits_

Calculates a rounded value with a specified number of decimal places.

coubic_

Calculates the cubic value.

ldexp_

Calculates a real number (double) from mantissa and exponent.

ldexpf_

Calculates a real number (float) from mantissa and exponent.

sinh_

Calculates the hyperbolic sine of the specified angle.

cosh_

Calculates the hyperbolic cosine of the specified angle.

tanh_

Calculates the hyperbolic tangent of the specified angle.

finite_

Determines whether the specified value is finite.

isnan_

Determines whether the specified value is not a number (NAN).

rands_

Calculates a pseudo random number between 0 and 32767. The parameter holdrand is set randomly and changed with every call.

Comments

The functions have the extension "_" (underscore), which identifies them as TwinCAT implementation.
Most are analog math.h, designed by Microsoft, only for the data type double.

See also

MSDN documentation of analog math.h functions.