maths

Maths provides some definitions of common mathematical procedures.

Note that "maths" should not be used with "numbers" from IPL, as the definitions of various procedures differ.

Procedures

ceiling (n)

Ceiling returns the smallest integer value not smaller than n.

For example:

  ceiling(2.5) => 3
  ceiling(-3.5) => -3

Parameters:

n
a numeric value

clamp (n, min_value, max_value)

Clamp ensures number is in range [min_value, max_value], returning min_value if number < min_value or max_value if number > max_value.

For example:

  clamp(3, 5, 10) => 5
  clamp(12, 5, 10) => 10
  clamp(7, 5, 10) => 7

Parameters:

n
a number to clamp within specified range
min_value
a number representing the lower limit of range
max_vaue
a number representing the upper limit of range

floor (n)

Floor returns the largest integer value not larger than n.

For example:

  floor(2.5) => 2
  floor(-3.5) => -4

Parameters:

n
a numeric value

maths_truncate (n)

Truncate returns the integer value closest to n whose absolute value is no larger than n.

Note, name to avoid conflict with Unicon's 'truncate' procedure.

For example:

  maths_truncate(2.5) => 2
  maths_truncate(-3.5) => -3

Parameters:

n
a numeric value

round (n)

Round returns the closest integer to n, rounding to even where n is half-way between two integers.

For example:

  round(2.5) => 2
  round(-3.5) => -4

Parameters:

n
a numeric value

Home