The following predefined arithmetic functions are available. E, E1 and E2 stand for arbitrary arithmetic expressions.
Function Description Argument Types Result ------------------------------------------------------------------------------ + E unary plus number number - E unary minus number number abs(E) absolute value number number sgn(E) sign value number integer floor(E) round down to integral value number number round(E) round to nearest integral value number number E1 + E2 addition number x number number E1 - E2 subtraction number x number number E1 * E2 multiplication number x number number E1 / E2 division number x number see below E1 // E2 integer division integer x integer integer E1 mod E2 modulus operation integer x integer integer E1 ^ E2 power operation number x number number min(E1,E2) minimum of 2 values number x number number max(E1,E2) maximum of 2 values number x number number \ E bitwise complement integer integer E1 /\ E2 bitwise conjunction integer x integer integer E1 \/ E2 bitwise disjunction integer x integer integer xor(E1,E2) bitwise exclusive disjunction integer x integer integer E1 >> E2 shift E1 right by E2 bits integer x integer integer E1 << E2 shift E1 left by E2 bits integer x integer integer sin(E) trigonometric function number float cos(E) trigonometric function number float tan(E) trigonometric function number float asin(E) trigonometric function number float acos(E) trigonometric function number float atan(E) trigonometric function number float exp(E) exponential function e^x number float ln(E) natural logarithm number float sqrt(E) square root number float pi the constant pi = 3.1415926... --- float e the constant e = 2.7182818... --- float fix(E) convert to integer (truncate) number integer float(E) convert to float number float rational(E) convert to rational number rational numerator(E) extract numerator of a rational integer or rational integer denominator(E) extract denominator of a rational integer or rational integer
Argument types other than specified yield a type error. As an argument type, number stands for integer, rational or float with the type conversions as specified above. As a result type, number stands for the more general of the argument types. float stands for single or double precision float, depending on the value of the float_precision flag. The division operator / yields either a rational or a float result, depending on the value of the global flag prefer_rationals. The same is true for the result of ^ if an integer is raised to a negative integral power.
The relation between integer division // and modulus operation mod is as follows:
X =:= (X mod Y) + (X // Y) * Y