math.math - ICE 0.1 API documentation

ICE 0.1 API documentation

# math.math

Math functions.

template epsilon(T)

  Get epsilon value for a numeric type.

pure bool equals(T)(const T a, const T b, const T tolerance = epsilon!(T));

  Fuzzy number equality test.

  Parameters:

  a | First number to compare.
  b | Secont number to compare.
  tolerance | Comparison tolerance.

  Returns:
  True if the numbers are equal, false otherwise.
pure T clamp(T)(const T v, const T minimum, const T maximum);

  Clamps a value to specified range.

  Parameters:

  v | Value to clamp.
  minimum | Minimum of the range.
  maximum | Maximum of the range.

  Returns:
  Clamped value.
void unittestClamp();

  Unittest for clamp() .

U round(U, T)(const T f);

  Round a number to the nearest integer of type U.

  Parameters:

  f | Float to round.

  Returns:
  Nearest int to given value.
U floor(U, T)(T f);

  Floor a number to an integer of type U.

  Parameters:

  f | Float to round. Must be less than U.max and more or equal to U.min .

  Returns:
  Floor of given value as U.
void unittestFloor();

  Unittest for floor.

uint[] powersOfTwo;

  Array of first 32 powers of 2.

void unittestGeneratePot();

  Unittest for generatePot().

uint potCeil(const uint num);

  Get the smallest power of two greater or equal to given number.

  Parameters:

  uint num | Number to get ceiling power of two to.

  Returns:
  Smallest power of two greater or equal to given number.
void unittestPotCeil();

  Unittest for potCeil.

bool isPot(const uint num);

  Determine if the given number is a power of two.

  Parameters:

  uint num | Number to check.

  Returns:
  True if the number is a power of two, false otherwise.
pure nothrow T alignToUpperMultipleOf(T)(const T mult, const T num);

  Align an unsigned integer to upper multiple of mult.

  Examples:

       assert(alignToUpperMultipleOf(4u, 11u)  == 12);
       assert(alignToUpperMultipleOf(4u, 12u)  == 12);
       assert(alignToUpperMultipleOf(5u, 256u) == 260);
       assert(alignToUpperMultipleOf(5u, 261u) == 265);
       assert(alignToUpperMultipleOf(1u, 261u) == 261);

  Parameters:

  mult | Multiplier to align to. Must not be 0.
  num | Number to align.

  Returns:
  Aligned result.

Copyright © Ferdinand Majerech 2011. | Page generated by AutoDDoc and Ddoc.