Table Of Contents

Previous topic

Byteswapping Functions

Next topic

Version Numbers

Math Functions

Basic math functions, macros and constants used in the Speect Engine.

Summary

S_ABS Get the absolute value of the given number.
S_MIN Get the minimum of two given values.
S_MAX Get the maximum of two given values.
S_NUM_LE Test if number is larger or equal to another number, A >= X.
S_NUM_SE Test if number is smaller or equal to another number, A <= X.
S_NUM_IN_RANGE Test if a number is in a range, X <= A <= Y.
s_rel_diff Get the relative difference between two floating point values.
s_float_equal Test if two floating point numbers are equal within a certain tolerance.
s_log2 Return the logarithm (base 2) of the given number.

Constants

define S_FLOAT_TOLERANCE
0.000001

Definition of floating point difference tollerance.

define S_PI
3.14159265358979323846

Definition of Pi to 20 decimal places.

Macros

macro S_ABS(X)

Get the absolute value of the given number.

Parameters:
  • X

    Number of which to get absolute value of.

Return:

Absolute value of X.

Note:

Macro is type independent.

macro S_MIN(X, Y)

Get the minimum of two given values.

Parameters:
  • X

    Number x.

  • Y

    Number y.

Return:

The minimum of X and Y.

Note:

Macro is type independent.

macro S_MAX(X, Y)

Get the maximum of two given values.

Parameters:
  • X

    Number x.

  • Y

    Number y.

Return:

The maximum of X and Y.

Note:

Macro is type independent.

macro S_NUM_LE(A, X)

Test if number is larger or equal to another number, A >= X.

Parameters:
  • A

    Number to test.

  • X

    Number to test against.

Return:

1 if A is larger or equal to X, else 0.

Note:

Macro is type independent.

macro S_NUM_SE(A, X)

Test if number is smaller or equal to another number, A <= X.

Parameters:
  • A

    Number to test.

  • X

    Number to test against.

Return:

1 if A is smaller or equal to X, else 0.

Note:

Macro is type independent.

macro S_NUM_IN_RANGE(A, X, Y)

Test if a number is in a range, X <= A <= Y.

Tests whether the given number lies in the given range (inclusive).

Parameters:
  • A

    The number to test.

  • X

    The left range boundary.

  • Y

    The right range boundary.

Return:

0 if not in range, else 1.

Note:

Macro is type independent.

Functions

double s_rel_diff(double a, double b)

Get the relative difference between two floating point values.

Relative distance is defined as the ratio of the difference to the larger of the two values.

Parameters:
  • a

    floating point value.

  • b

    floating point value.

Return:

Relative difference between a and b.

s_bool s_float_equal(double a, double b)

Test if two floating point numbers are equal within a certain tolerance.

If the relative difference (s_rel_diff) between the two values are less or equal to S_FLOAT_TOLERANCE then they are equal.

Parameters:
  • a

    floating point value.

  • b

    floating point value.

Return:

TRUE or FALSE.

double s_log2(double a)

Return the logarithm (base 2) of the given number.

Parameters:
  • a

    floating point value of which to calculate log2.

Return:

logarithm (base 2) or -HUGE_VAL if a is s_float_equal to 0.