MATH
signature
signature MATH
structure Math
:> MATH
where type real = Real.real
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.
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
val pi : real
val e : real
sqrt x
sqrt
(~0.0) = ~0.0
. If x < 0, it returns NaN.
sin x
cos x
tan x
tan
will produce infinities at various finite values, roughly corresponding to the singularities of the tangent function.
asin x
acos x
asin
is the inverse of sin
. Its result is guaranteed to be in the closed interval [-pi/2,pi/2]. acos
is the inverse of cos
. Its result is guaranteed to be in the closed interval [0,pi]. If the magnitude of x exceeds 1.0, they return NaN.
atan x
atan
is the inverse of tan
. For finite arguments, the result is guaranteed to be in the open interval (-pi/2,pi/2). If x is +infinity, it returns pi/2; if x is -infinity, it returns -pi/2.
atan2 (y, x)
(y/x)
in the closed interval [-pi,pi], corresponding to angles within +-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 (x,y). When x = 0, this corresponds to an angle of 90 degrees, and the result is (real (sign y)) * pi/2.0
. It holds that
andsign
(cos
(atan2
(y,x))) =sign
(x)
except for inaccuracies incurred by the finite precision ofsign
(sin
(atan2
(y,x))) =sign
(y)
real
and the approximation algorithms used to compute the mathematical functions.
Rules for exceptional cases are specified in the following table.
y | x | atan2(y,x) |
---|---|---|
+-0 | 0 < x | +-0 |
+-0 | +0 | +-0 |
+-0 | 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 | 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)
.
These functions have the following properties:
sinh +-0
| = | +-0 |
sinh +-infinity
| = | +-infinity |
cosh +-0
| = | 1 |
cosh +-infinity
| = | +-infinity |
tanh +-0
| = | +-0 |
tanh +-infinity
| = | +-1 |
REAL
Generated April 12, 2004
Last Modified May 25, 2000
Comments to John Reppy.
This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.
Copyright © 2004 AT&T and Lucent Technologies. All rights reserved.
Permission is granted for internet users to make one paper copy for their
own personal use. Further hardcopy reproduction is strictly prohibited.
Permission to distribute the HTML document electronically on any medium
other than the internet must be requested from the copyright holders by
contacting the editors.
Printed versions of the SML Basis Manual are available from Cambridge
University Press.
To order, please visit
www.cup.org (North America) or
www.cup.cam.ac.uk (outside North America). |