# Common Scalar Functions

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.

1. ## Common constants known to the core

   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

2. ## Common single precision support functions

   1. ### absf(float a) returns float

      absf returns the positive value of a

      Example values:

      - absf(-1.5)=1.5
      - absf(1)=1
      - absf(0)=0

   2. ### ceilf(float a) returns float

      ceilf returns the next (to the right) natural number to a

      Example values:

      - ceilf(-1.5)=-1
      - ceilf(1.5)=2
      - ceilf(0)=1

   3. ### roundf(float a) returns float

      roundf returns the rounded value of a

      Example values:

      - roundf(-1.5)=-2
      - roundf(1.4)=1
      - roundf(1)=1

   4. ### floorf(float a) returns float

      floorf returns the previous (to the left) natural number to a

      Example values:

      - floorf(-1.5)=-2
      - floorf(1.5)=1
      - floorf(0)=0

   5. ### modf(float a, float b) returns float

      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:

      - modf(7,3)=1
      - modf(5,1.5)=0.5

3. ## Single precision log and exp functions

   If you need some background around this functions, check out

   http://en.wikipedia.org/wiki/Logarithm

   http://en.wikipedia.org/wiki/Exponentiation

   1. ### sqrtf(float a) returns float

      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:

      - sqrtf(2)=1.41421
      - sqrtf(3)=1.73205

   2. ### powf(float a, float b) returns float

      powf returns the value ab

      Example values:

      - powf(2,3)=8
      - powf(2,0.5)=1.41421

   3. ### expf(float a) returns float

      expf returns the value ea

      Example values:

      - expf(0)=1
      - expf(1)=2.71828
      - expf(-1)=0.36787

   4. ### exp2f(float a) returns float

      exp2f returns the value 2a

      Example values:

      - exp2f(0)=1
      - exp2f(1)=2
      - exp2f(-1)=0.5

   5. ### exp10f(float a) returns float

      exp10f returns the value 10a

      Example values:

      - exp10f(0)=1
      - exp10f(1)=10
      - exp10f(-1)=0.1

   6. ### logf(float a) returns float

      logf returns the value log(a)

      log is only defined for a>0, so in other cases an exception is thrown (TODO)

      Example values:

      - logf(1)=0
      - logf(2.71828)=1

   7. ### log2f(float a) returns float

      log2f returns the value of log2(a)

      Example values:

      - log2f(1)=0
      - log2f(2)=1

   8. ### log10f(float a) returns float

      log10f returns the value of log10(a)

      Example values:

      - log10f(1)=0
      - log10f(10)=1

4. ## Single precision trigonometric functions

   If you need some background around this functions, check out

   http://en.wikipedia.org/wiki/Sine

   http://en.wikipedia.org/wiki/Inverse_trigonometric_function

   1. ### sinf(float a) returns float

      Returns the sine value of a, which is in the range of -1<result<1

   2. ### cosf(float a) returns float

      Returns the cosine value of a, which is in the range of -1<result<1

   3. ### tanf(float a) returns float

      Returns the tangent value of a, which is in the range of -∞<result<∞

   4. ### asinf(float a) returns float

      Returns the inverted sine value of a, which is in the range of -π/2<result<π/2

   5. ### acosf(float) returns float

      Returns the inverted cosine value of a, which is in the range of 0<result<π

   6. ### atanf(float a) returns float

      Returns the inverted tangent value of a

      This function only returns values of -π/2<result<π/2

   7. ### atan2f(float a, float b) returns float

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

   8. ### hypotf(float a, float b) returns float

      Returns the length of the hypotenuse of a right side triangle with the side a and b

5. ## Single precision hyperbolic functions

   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

   1. ### sinhf(float a) returns float

      Returns hyperbolic sine value of a

   2. ### coshf(float a) returns float

      Returns the hyperbolic cosine value of a

   3. ### tanhf(float a) returns float

      Returns the hyperbolic tangent value of a

   4. ### asinhf(float) returns float

      Returns the inverted hyperbolic sine value of a

   5. ### acoshf(float) returns float

      Returns the inverted hyperbolic cosine value of a

   6. ### atanhf(float) returns float

      Returns the inverted hyperbolic tangent value of a