TKS itself already provides the builtin datatype float, which is the base for all single precision functions and classes. Additionally there is support for the single precision Float class and the double precision Double class.
Beware that float values use 32bit and thus their precision is not really well. Especially when using a lot of multiplications/divisions, the resulting value might not be exactly what you would have been expecting. Also values like 1/3 and 0.1 cannot be exactly represented by a float value, as their memory usage is quite finite.
Float comparison in TKS is automatically done with an epsilon range check to take care of redundant values of which the float datatype is well known for.
There is a set of common constants supplied by the TKS Yac Interface, it is more or less taken from the gcc math.h library include file:
Constant Name |
Constant Value |
Constant Formula |
M_E | 2.7182818284590452354f | e |
M_LOG2E | 1.4426950408889634074f | 1/log(2) |
M_LOG10E | 0.43429448190325182765f | 1/log(10) |
M_LN2 | 0.69314718055994530942f | log(2) |
M_LN10 | 2.30258509299404568402f | log(10) |
M_PI | 3.14159265358979323846f | π |
M_PI_2 | 1.57079632679489661923f | π/2 |
M_PI_4 | 0.78539816339744830962f | π/4 |
M_1_PI | 0.31830988618379067154f | 1/π |
M_2_PI | 0.63661977236758134308f | 2/π |
M_2_SQRTPI | 1.12837916709551257390f | 2/√π |
M_SQRT2 | 1.41421356237309504880f | √2 |
M_SQRT1_2 | 0.70710678118654752440f | 1/√2 |
absf returns the positive value of a
Example values:
ceilf returns the next (to the right) natural number to a
Example values:
roundf returns the rounded value of a
Example values:
floorf returns the previous (to the left) natural number to a
Example values:
modf returns the remainder of the division a/b
The result is undefined if b is 0, an exception will be thrown in this case. (TODO: commonmath hasnt yet exception usage implemented)
Example values:
If you need some background around this functions, check out
http://en.wikipedia.org/wiki/Logarithm
http://en.wikipedia.org/wiki/Exponentiation
sqrtf returns the square root of the value a.
The result is undefined if (a<0) for this function, an excpetion will be thrown in this case (TODO).
Example values:
powf returns the value ab
Example values:
expf returns the value ea
Example values:
exp2f returns the value 2a
Example values:
exp10f returns the value 10a
Example values:
logf returns the value log(a)
log is only defined for a>0, so in other cases an exception is thrown (TODO)
Example values:
log2f returns the value of log2(a)
Example values:
log10f returns the value of log10(a)
Example values:
If you need some background around this functions, check out
http://en.wikipedia.org/wiki/Sine
http://en.wikipedia.org/wiki/Inverse_trigonometric_function
Returns the sine value of a, which is in the range of -1<result<1
Returns the cosine value of a, which is in the range of -1<result<1
Returns the tangent value of a, which is in the range of -∞<result<∞
Returns the inverted sine value of a, which is in the range of -π/2<result<π/2
Returns the inverted cosine value of a, which is in the range of 0<result<π
Returns the inverted tangent value of a
This function only returns values of -π/2<result<π/2
Returns the inverted tangent value of a/b.
This function checks the signs of a and b and thus is capable of returning in the range of -π<result<π
Returns the length of the hypotenuse of a right side triangle with the side a and b
If you need some background around this functions, check out
http://en.wikipedia.org/wiki/Hyperbolic_function
http://en.wikipedia.org/wiki/Inverse_hyperbolic_function
Returns hyperbolic sine value of a
Returns the hyperbolic cosine value of a
Returns the hyperbolic tangent value of a
Returns the inverted hyperbolic sine value of a
Returns the inverted hyperbolic cosine value of a
Returns the inverted hyperbolic tangent value of a