Math module

This module contains the required functions to perform common numeric operations such as exponential, logarithm, square root, trigonometric or hyperbolic functions. These functions only accept numbers as input and return numbers. They are only available in the modeling language, and they can’t be used with solver expressions. You must use the dedicated operators for that.

All invalid operations like sqrt(-1) or cos(+inf) never throw exceptions. When such cases appear, the functions of this module return nan.

Note

To use the features of this module, you have to put a special import statement at the begining of your HXM file: use math;

Constants

This module defines the following constants:

math.PI

The mathematical constant π = 3.141592653589793.

math.E

The mathematical constant e = 2.718281828459045

Common functions

math.abs(val)

Returns the absolute value of the argument.

math.ceil(val)

Returns the ceiling of x, i.e the smallest integer value greater than or equal to the given value. The result is casted to an integer. If the given value is already an integer, the argument is simply returned.

If the final result is out of the range of integers (e.g math.ceil(+inf)), an exception is thrown.

math.floor(val)

Returns the floor of x, i.e the largest integer value less than or equal to the given value. The result is casted to an integer. If the given value is already an integer, the argument is simply returned.

If the final result is out of the range of integers (e.g math.floor(+inf)), an exception is thrown.

math.round(val)

Returns the closest integer to the given value. The result is casted to an integer. If the given value is already an integer, the argument is simply returned.

If the final result is out of the range of integers (e.g math.round(+inf)), an exception is thrown.

math.isInf(val)

Returns true if the given value is positive or negative infinity (+inf or -inf). Please note that the given value must be a float or an integer. This function will throw an exception otherwise.

math.isNan(val)

Returns true if the given value is a nan (Not a Number). Please note that the given value must be a float or an integer. This function will throw an exception otherwise.

Power and logarithm functions

math.exp(val)

Returns Euler’s number e raised to the power of the given value. Special cases:

  • If the value is nan, the result is nan.

  • If the value is +inf, then the result is +inf.

  • If the value is -inf, then the result is positive zero.

  • If the final result overflow, then +inf is returned.

math.pow(base, exponent)
math.log(val)

Returns the logarithm (base e) of the given value. Special cases:

  • If the value is nan or less than zero, then the result is nan.

  • If the value is +inf, then the result is +inf.

  • If the value is zero (positive or negative), then the result is -inf.

math.log10(val)

Returns the logarithm (base 10) of the given value. Special cases:

  • If the value is nan or less than zero, then the result is nan.

  • If the value is +inf, then the result is +inf.

  • If the value is zero (positive or negative), then the result is -inf.

math.log2(val)

Returns the logarithm (base 2) of the given value. Special cases:

  • If the value is nan or less than zero, then the result is nan.

  • If the value is +inf, then the result is +inf.

  • If the value is zero (positive or negative), then the result is -inf.

math.sqrt(val)

Returns the square root of a the given value. Special cases:

  • If the value is nan or less than zero, the result is nan.

  • If the value is +inf, the result is +inf.

Trigonometric functions

math.cos(val)

Returns the trigonometric cosine of an angle. If the argument is nan, +inf or -inf, then the result is nan.

math.sin(val)

Returns the trigonometric sine of an angle. Special cases:

  • If the argument is nan, +inf or -inf, then the result is nan.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.

math.tan(val)

Returns the trigonometric tangent of an angle. If the argument is nan, +inf or -inf, then the result is nan.

math.acos(val)

Returns the arc cosine of the given value. The result is in the range 0.0 through π. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is greater than 1.0 or less than 1.0, then the result is nan.

math.asin(val)

Returns the arc sine of the given value. The result is in the range 0.0 through π. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is greater than 1.0 or less than 1.0, then the result is nan.

math.atan(val)

Returns the arc tangent of the given value. The result is in the range -π/2 through π/2. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.

Hyperbolic functions

math.cosh(val)

Returns the hyperbolic cosine of the given value. This function is equivalent to (e^x + e^-x)/2. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is +inf, then the result is +inf.

  • If the argument is -inf, then the result is +inf.

  • If the argument is zero, then the result is 1.0.

math.sinh(val)

Returns the hyperbolic sine of the given value. This function is equivalent to (e^x - e^-x)/2. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is +inf, then the result is +inf.

  • If the argument is -inf, then the result is -inf.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.

math.tanh(val)

Returns the hyperbolic tangent of the given value. This function is equivalent to sinh(x)/cosh(x). Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.

  • If the argument is +inf, then the result is +1.0.

  • If the argument is -inf, then the result is -1.0.

math.acosh(val)

Returns the inverse hyperbolic cosine of the given value. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is less than 1.0, then the result is nan.

math.asinh(val)

Returns the inverse hyperbolic sine of the given value. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.

math.atanh(val)

Returns the inverse hyperbolic tangent of the given value. Special cases:

  • If the argument is nan, then the result is nan.

  • If the argument is positive zero, then the result is positive zero.

  • If the argument is negative zero, then the result is negative zero.