MATH
signature
The signature MATH specifies basic mathematical constants, the square root function, and trigonometric, hyperbolic, exponential and logarithmic functions based on a real type. The functions defined here have roughly the same semantics as their counterparts in ISO C's math.h
.
The top-level structure Math provides these functions for the default real type Real.real.
In the functions below, unless specified otherwise, if any argument is a NaN, the return value is a NaN. In a list of rules specifying the behavior of a function in special cases, the first matching rule defines the semantics.
signature MATH
structure Math
: MATH
type real
val pi : real
val e : real
val sqrt : real -> real
val sin : real -> real
val cos : real -> real
val tan : real -> real
val asin : real -> real
val acos : real -> real
val atan : real -> real
val atan2 : (real * real) -> real
val exp : real -> real
val pow : (real * real) -> real
val ln : real -> real
val log10 : real -> real
val sinh : real -> real
val cosh : real -> real
val tanh : real -> real
type real
pi
e
sqrt x
sqrt (~0) = ~0
. If x < 0, returns NaN.
sin x
cos x
tan x
asin x
acos x
atan x
atan2 (y, x)
(y / x)
in the closed interval [-pi,pi], corresponding to angles of +-180 degrees. The quadrant of the resulting angle is determined using the signs of both x and y, and is the same as the quadrant of the point (y,x). When x = 0, this corresponds to an angle of 90 degrees, and the result is sign
(y * pi/2). It holds that
andsign
(cos
(atan2
(y,x))) =sign
x
except for inaccuracies incurred by the finite precision of real and the approximation algorithms used to compute the mathematical functions.sign
(sin
(atan2
(y,x))) =sign
y
Rules for exceptional cases are specified in the following table.
y | x | atan2(y,x) |
---|---|---|
+-0 | x, 0 < x | +-0 |
+-0 | +0 | +-0 |
+-0 | x, x < 0 | +-pi |
+-0 | -0 | +-pi |
y, 0 < y | +-0 | pi/2 |
y, y < 0 | +-0 | -pi/2 |
+-y, finite y > 0 | +infinity | +-0 |
+-y, finite y > 0 | -infinity | +-pi |
+-infinity | x, finite x | +-pi/2 |
+-infinity | +infinity | +-pi/4 |
+-infinity | -infinity | +-3pi/4 |
exp x
pow (x, y)
x | y | pow(x,y) |
---|---|---|
x, including NaN | 0 | 1 |
|x| > 1 | +infinity | +infinity |
|x| < 1 | +infinity | +0 |
|x| > 1 | -infinity | +0 |
|x| < 1 | -infinity | +infinity |
+infinity | y > 0 | +infinity |
+infinity | y < 0 | +0 |
-infinity | y > 0, odd integer | -infinity |
-infinity | y > 0, not odd integer | +infinity |
-infinity | y < 0, odd integer | -0 |
-infinity | y < 0, not odd integer | +0 |
x | NaN | NaN |
NaN | y <> 0 | NaN |
+-1 | +-infinity | NaN |
finite x < 0 | finite non-integer y | NaN |
+-0 | y < 0, odd integer | +-infinity |
+-0 | finite y < 0, not odd integer | +infinity |
+-0 | y > 0, odd integer | +-0 |
+-0 | y > 0, not odd integer | +0 |
ln x
log10 r
sinh x
cosh x
tanh x
(sinh x) / (cosh x)
.
For infinities, we have sinh
+-infinity = +-infinity, cosh
+-infinity = +infinity and tanh
+-infinity = +-1.
REAL
Last Modified May 15, 1996
Comments to John Reppy.
Copyright © 1997 Bell Labs, Lucent Technologies