Math

Usage

use Math;

or

import Math;

This module provides less frequently used mathematical constants and functions.

It includes wrappers for many of the constants and functions in the C Math library, which is part of the C Language Standard (ISO/IEC 9899) as described in Section 7.12. Please consult that standard for an authoritative description of the expected properties of those constants and routines.

In general, where the C math library provides a double and a float version of a function, the float version has a suffix ‘f’. In the Chapel interface, the suffix is dropped, and the type of the operand determines which version is called – according to the usual function overloading and resolution rules. Normally, the result has the same precision as the argument(s). Please consult the C standard for specifics.

Error Handling – At present, Chapel does not provide control over error handling in the Math module. The default behavior is as if the macro math_errhandling is set to 0: Given erroneous input at run-time, all math functions will return an implementation-defined value; no exception will be generated.

Trigonometric Functions

acos acosh asin asinh atan atan2 atanh cos cosh sin sinh tan tanh

Log Functions

log log10 log1p logBasePow2 log2

Exponential Functions

exp exp2 expm1 ldexp

Gamma Functions

lgamma tgamma

Error Functions

erf erfc

Algorithms

gcd

Bessel Functions

j0 j1 jn y0 y1 yn

Constant and Function Definitions

param e = 2.7182818284590452354

e - exp(1) or the base of the natural logarithm

param log2_e = 1.4426950408889634074

log2(e)

param log10_e = 0.43429448190325182765

log10(e)

param ln_2 = 0.69314718055994530942

log(2) (natural logarithm)

param ln_10 = 2.30258509299404568402

log(10) (natural logarithm)

param pi = 3.14159265358979323846

pi - the circumference/the diameter of a circle

param half_pi = 1.57079632679489661923

pi/2

param quarter_pi = 0.78539816339744830962

pi/4

param recipr_pi = 0.31830988618379067154

1/pi

param twice_recipr_pi = 0.63661977236758134308

2/pi

param twice_recipr_sqrt_pi = 1.12837916709551257390

2/sqrt(pi)

param sqrt_2 = 1.41421356237309504880

sqrt(2)

param recipr_sqrt_2 = 0.70710678118654752440

1/sqrt(2)

proc acos(x: real(64)): real(64)

Returns the arc cosine of the argument x.

It is an error if x is less than -1 or greater than 1.

proc acos(x: real(32)): real(32)

Returns the arc cosine of the argument x.

It is an error if x is less than -1 or greater than 1.

proc acos(z: complex(64)): complex(64)

Returns the arc cosine of the argument z.

proc acos(z: complex(128)): complex(128)

Returns the arc cosine of the argument z.

proc acosh(x: real(64)): real(64)

Returns the inverse hyperbolic cosine of the argument x.

It is an error if x is less than 1.

proc acosh(x: real(32)): real(32)

Returns the inverse hyperbolic cosine of the argument x.

It is an error if x is less than 1.

proc acosh(z: complex(64)): complex(64)

Returns the inverse hyperbolic cosine of the argument z.

proc acosh(z: complex(128)): complex(128)

Returns the inverse hyperbolic cosine of the argument z.

proc asin(x: real(64)): real(64)

Returns the arc sine of the argument x.

It is an error if x is less than -1 or greater than 1.

proc asin(x: real(32)): real(32)

Returns the arc sine of the argument x.

It is an error if x is less than -1 or greater than 1.

proc asin(z: complex(64)): complex(64)

Returns the arc sine of the argument z.

proc asin(z: complex(128)): complex(128)

Returns the arc sine of the argument z.

proc asinh(x: real(64)): real(64)

Returns the inverse hyperbolic sine of the argument x.

proc asinh(x: real(32)): real(32)

Returns the inverse hyperbolic sine of the argument x.

proc asinh(z: complex(64)): complex(64)

Returns the inverse hyperbolic sine of the argument z.

proc asinh(z: complex(128)): complex(128)

Returns the inverse hyperbolic sine of the argument z.

proc atan(x: real(64)): real(64)

Returns the arc tangent of the argument x.

proc atan(x: real(32)): real(32)

Returns the arc tangent of the argument x.

proc atan(z: complex(64)): complex(64)

Returns the arc tangent of the argument z.

proc atan(z: complex(128)): complex(128)

Returns the arc tangent of the argument z.

proc atan2(y: real(64), x: real(64)): real(64)

Returns the arc tangent of the ratio of the two arguments.

This is equivalent to the arc tangent of y / x except that the signs of y and x are used to determine the quadrant of the result.

proc atan2(y: real(32), x: real(32)): real(32)

Returns the arc tangent of the two arguments.

This is equivalent to the arc tangent of y / x except that the signs of y and x are used to determine the quadrant of the result.

proc atanh(x: real(64)): real(64)

Returns the inverse hyperbolic tangent of the argument x.

It is an error if x is less than -1 or greater than 1.

proc atanh(x: real(32)): real(32)

Returns the inverse hyperbolic tangent of the argument x.

It is an error if x is less than -1 or greater than 1.

proc atanh(z: complex(64)): complex(64)

Returns the inverse hyperbolic tangent of the argument z.

proc atanh(z: complex(128)): complex(128)

Returns the inverse hyperbolic tangent of the argument z.

proc cos(x: real(64)): real(64)

Returns the cosine of the argument x.

proc cos(x: real(32)): real(32)

Returns the cosine of the argument x.

proc cos(z: complex(64)): complex(64)

Returns the cosine of the argument z.

proc cos(z: complex(128)): complex(128)

Returns the cosine of the argument z.

proc cosh(x: real(64)): real(64)

Returns the hyperbolic cosine of the argument x.

proc cosh(x: real(32)): real(32)

Returns the hyperbolic cosine of the argument x.

proc cosh(z: complex(64)): complex(64)

Returns the hyperbolic cosine of the argument z.

proc cosh(z: complex(128)): complex(128)

Returns the hyperbolic cosine of the argument z.

proc erf(x: real(64)): real(64)

Returns the error function of the argument x.

proc erf(x: real(32)): real(32)

Returns the error function of the argument x.

proc erfc(x: real(64)): real(64)

Returns the complementary error function of the argument. This is equivalent to 1.0 - erf(x).

proc erfc(x: real(32)): real(32)

Returns the complementary error function of the argument. This is equivalent to 1.0 - erf(x).

proc exp(x: real(64)): real(64)

Returns the value of the Napierian e raised to the power of the argument x.

proc exp(x: real(32)): real(32)

Returns the value of the Napierian e raised to the power of the argument.

proc exp(z: complex(64)): complex(64)

Returns the value of the Napierian e raised to the power of the argument.

proc exp(z: complex(128)): complex(128)

Returns the value of the Napierian e raised to the power of the argument.

proc exp2(x: real(64)): real(64)

Returns the value of 2 raised to the power of the argument x.

proc exp2(x: real(32)): real(32)

Returns the value of 2 raised to the power of the argument x.

proc expm1(x: real(64)): real(64)

Returns one less than the value of the Napierian e raised to the power of the argument x.

proc expm1(x: real(32)): real(32)

Returns one less than the value of the Napierian e raised to the power of the argument x.

proc ldexp(x: real(64), n: int(32)): real(64)

Multiply by an integer power of 2. Returns x * 2**n.

proc ldexp(x: real(32), n: int(32)): real(32)
proc lgamma(x: real(64)): real(64)

Returns the natural logarithm of the absolute value of the gamma function of the argument x.

proc lgamma(x: real(32)): real(32)

Returns the natural logarithm of the absolute value of the gamma function of the argument x.

proc log(x: real(64)): real(64)

Returns the natural logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log(x: real(32)): real(32)

Returns the natural logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log(z: complex(64)): complex(64)

Returns the natural logarithm of the argument z.

proc log(z: complex(128)): complex(128)

Returns the natural logarithm of the argument z.

proc log10(x: real(64)): real(64)

Returns the base 10 logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log10(x: real(32)): real(32)

Returns the base 10 logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log1p(x: real(64)): real(64)

Returns the natural logarithm of x + 1.

It is an error if x is less than or equal to -1.

proc log1p(x: real(32)): real(32)

Returns the natural logarithm of x + 1.

It is an error if x is less than or equal to -1.

proc logBasePow2(val: int(?w), baseLog2)

Returns the log to the base 2**baseLog2 of the given in value. If baseLog2 is 1, then returns the log to the base 2; if baseLog2 is 2, then returns the log to the base 4, etc. Any fractional part is discarded.

Return type

int

proc logBasePow2(val: uint(?w), baseLog2)

Returns the log to the base 2**baseLog2 of the given in value. If baseLog2 is 1, then returns the log to the base 2; if baseLog2 is 2, then returns the log to the base 4, etc. Any fractional part is discarded.

Return type

int

proc log2(x: real(64)): real(64)

Returns the base 2 logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log2(x: real(32)): real(32)

Returns the base 2 logarithm of the argument x.

It is an error if x is less than or equal to zero.

proc log2(val: int(?w))

Returns the base 2 logarithm of the argument x, rounded down.

Return type

int

It is an error if x is less than or equal to zero.

proc log2(val: uint(?w))

Returns the base 2 logarithm of the argument x, rounded down.

Return type

int

It is an error if x is less than or equal to zero.

proc sin(x: real(64)): real(64)

Returns the sine of the argument x.

proc sin(x: real(32)): real(32)

Returns the sine of the argument x.

proc sin(z: complex(64)): complex(64)

Returns the sine of the argument z.

proc sin(z: complex(128)): complex(128)

Returns the sine of the argument z.

proc sinh(x: real(64)): real(64)

Returns the hyperbolic sine of the argument x.

proc sinh(x: real(32)): real(32)

Returns the hyperbolic sine of the argument x.

proc sinh(z: complex(64)): complex(64)

Returns the hyperbolic sine of the argument z.

proc sinh(z: complex(128)): complex(128)

Returns the hyperbolic sine of the argument z.

proc tan(x: real(64)): real(64)

Returns the tangent of the argument x.

proc tan(x: real(32)): real(32)

Returns the tangent of the argument x.

proc tan(z: complex(64)): complex(64)

Returns the tangent of the argument z.

proc tan(z: complex(128)): complex(128)

Returns the tangent of the argument z.

proc tanh(x: real(64)): real(64)

Returns the hyperbolic tangent of the argument x.

proc tanh(x: real(32)): real(32)

Returns the hyperbolic tangent of the argument x.

proc tanh(z: complex(64)): complex(64)

Returns the hyperbolic tangent of the argument z.

proc tanh(z: complex(128)): complex(128)

Returns the hyperbolic tangent of the argument z.

proc tgamma(x: real(64)): real(64)

Returns the absolute value of the gamma function of the argument x.

proc tgamma(x: real(32)): real(32)

Returns the absolute value of the gamma function of the argument x.

proc gcd(in a: int, in b: int): int

Returns the greatest common divisor of the integer argument a and b.

proc j0(x: real(32)): real(32)

Returns the Bessel function of the first kind of order 0 of x.

proc j0(x: real(64)): real(64)

Returns the Bessel function of the first kind of order 0 of x.

proc j1(x: real(32)): real(32)

Returns the Bessel function of the first kind of order 1 of x.

proc j1(x: real(64)): real(64)

Returns the Bessel function of the first kind of order 1 of x.

proc jn(n: int, x: real(32)): real(32)

Returns the Bessel function of the first kind of order n of x.

proc jn(n: int, x: real(64)): real(64)

Returns the Bessel function of the first kind of order n of x.

proc y0(x: real(32)): real(32)

Returns the Bessel function of the second kind of order 0 of x, where x must be greater than 0

proc y0(x: real(64)): real(64)

Returns the Bessel function of the second kind of order 0 of x, where x must be greater than 0

proc y1(x: real(32)): real(32)

Returns the Bessel function of the second kind of order 1 of x, where x must be greater than 0

proc y1(x: real(64)): real(64)

Returns the Bessel function of the second kind of order 1 of x, where x must be greater than 0

proc yn(n: int, x: real(32)): real(32)

Returns the Bessel function of the second kind of order n of x, where x must be greater than 0

proc yn(n: int, x: real(64)): real(64)

Returns the Bessel function of the second kind of order n of x, where x must be greater than 0