# 13.10 Math Interface

```ORIGIN 'betaenv';
LIB_DEF 'math' '../lib';
(*
*       Copyright (C) Mjolner Informatics, 1984-96
*
* Math.bet: mathematical functions
*
* This library provides mathematical patterns: trigonometric,
* hyperbolic, exponential and logarithmic, floating point
* manipulation and miscellaneous constants.
*)
--- LIB: Attributes ---

(* miscellaneous constants *)

e:       (# Exit 2.7182818284590452354 #);
log2e:   (# Exit 1.4426950408889634074 #);
log10e:  (# Exit 0.43429448190325182765 #);
ln2:     (# Exit 0.69314718055994530942 #);
ln10:    (# Exit 2.30258509299404568402 #);
pi:      (# Exit 3.14159265358979323846 #);
pihalf:  (# Exit 1.57079632679489661923 #);
piforth: (# Exit 0.78539816339744830962 #);

(* trigonometric functions *)

acos: external
(* returns the arccosine of x in radians, in the range 0 to pi.  If
* x is a NaN (Not-a-Number) or if the absolute value of x exceeds
* 1.0, acos(x) returns a NaN.  Invalid operation/DOMAIN error is
* signaled if x is a NaN or if |x| > 1.0.
*)
(# x,res: @Real;
enter x
exit res
#);
asin: external
(* returns the arcsine of x in radians, in the range -pi/2 to pi/2.
* If x is a NaN or if the absolute value of x exceeds 1.0, asin
* returns a NaN.  Invalid operation/DOMAIN error is signaled if x
* is a NaN or if |x| > 1.0.
*)
(# x,res: @Real;
enter x
exit res
#);
atan: external
(* returns the arctangent of x, in the range of -pi/2 to pi/2
* radians.  If x = +-infinity, then atan(x) returns +-pi/2.  If x
* is +- 0, then atan returns x. If x is a NaN, then atan returns a
* NaN.  An invalid operation/DOMAIN error is signaled by atan only
* if x is a NaN.
*)
(# x,res: @Real;
enter x
exit res
#);
atan2: external
(* returns the arctangent of y/x in radians, in the range -pi to
* pi, using the signs of both arguments to determine the quadrant
* of the return value.
*
* If x is a NaN or if y is a NaN or if both x and y are infinities,
* atan2 returns a NaN.  If both x and y are zero, atan2 returns
* zero.  Invalid operation/DOMAIN error is signaled by atan2 if
* both x and y are infinite or if either x or y is a NaN.
*)
(# y,x,res: @Real;
enter (y,x)
exit res
#);
cos: external
(* computes the cosine of x, where x is expressed in radians.
*
* The cos function uses an argument reduction based on the
* remainder function and pi.  The cos function is periodic with
* respect to pi, so its period differs slightly from its
* mathematical counterpart and diverges from its counterpart when
* the argument becomes very large.
*
* If x is infinite or a NaN, then cos returns a NaN and signals
* invalid/DOMAIN error.
*)
(# x,res: @Real;
enter x
exit res
#);
sin: external
(* computes the sine of x, where x is expressed in radians.
*
* The sin function uses an argument reduction based on the
* remainder function and pi.  The sin function is periodic with
* respect to pi, so its period differs slightly from its
* mathematical counterpart and diverges from its counterpart when
* the argument becomes very large.
*
* If x is infinite or a NaN, then sin returns a NaN and signals
*    invalid/DOMAIN error.
*)
(# x,res: @Real;
enter x
exit res
#);
tan: external
(* computes the tangent of x, where x is expressed in radians.
*
* The tan function uses an argument reduction based on the
* remainder function and pi The tan function is periodic with
* respect to pi, so its period differs slightly from its
* mathematical counterpart and diverges from its counterpart when
* the argument becomes very large.
*)
(# x,res: @Real;
enter x
exit res
#);

(* hyperbolic functions *)

cosh: external
(* returns the hyberbolic cosine of x.
*
* If x is a NaN, cosh returns a NaN.
*)
(# x,res: @Real;
enter x
exit res
#);
sinh: external
(* returns the hyberbolic sine of x.
*
* If x is a NaN, sinh returns a NaN.
*)
(# x,res: @Real;
enter x
exit res
#);
tanh: external
(* returns the hyberbolic tangent of x.
*
* If x is a NaN, tanh returns a NaN.
*)
(# x,res: @Real;
enter x
exit res
#);

(* exponential and logarithmic functions *)

exp: external
(* returns the base-e or natural exponential e^x.
*
* Special cases for exp:
*
* If x = +infinity, then exp returns +infinity and does not signal
* an exception.  If x = ­infinity, then exp returns 0 and does not
* signal an exception.  If x is a NaN, then exp returns a NaN.
*)
(# x,res: @Real;
enter x
exit res
#);
ldexp: external
(* returns the quantity x * 2^exp. *)
(# x,res: @Real;
exp: @Integer;
enter (x,exp)
exit res
#);
log: external
(* returns the base e or natural logarithm of its argument x.
*
* Special cases for log:
*
* If x is +infinity, then log returns +infinity and signals no
* exceptions.  If x is 0, then log returns -infinity and signals
* divide-by-zero.  If x < 0, then log returns a NaN and signals
* invalid/DOMAIN error.
*)
(# x,res: @Real;
enter x
exit res
#);
log10: external
(* returns the base 10 logarithm of x.
*
* If x is a NaN or is negative, log10 returns a NaN. If x is
* +infinity, log10(x) returns +infinity.  If x is zero, log10
* returns -infinity and signals divide by zero/SING error.
*)
(# x,res: @Real;
enter x
exit res
#);

(* floating point manipulation *)

modf: external
(* returns the fractional part of x and stores the integral part
* indirectly in the location pointed to by ipPtr.  Both the return
* value and the value stored in ipPtr share the same sign as x.
*
* If x is infinite, modf returns a zero with the sign of x and sets
* ipPtr to x.  If x is a NaN, mod returns a NaN and sets ipPtr to
* the same NaN.
*)
(# x,res: @Real;
ipPtr: @Integer;
enter (x,ipPtr)
exit res
#);
pow: external
(* returns x^y *)
(# x,y,res: @Real;
enter (x,y)
exit res
#);
sqrt: external
(* computes the square root of x.
*
* Special cases for sqrt:
*
* If x is a NaN, sqrt returns a NaN and signals no exceptions.  If
* x is a NaN or if x < 0, sqrt returns a NaN and signals invalid
* operation/DOMAIN error.
*)
(# x,res: @Real;
enter x
exit res
#);
ceil: external
(* returns the smallest integer value (in real format) not less
* than x.
*
* If x is a NaN, ceil returns a NaN.  If x is infinite, ceil
* returns x.  Invalid operation is signaled by ceil if x is a NaN.
* If x is a non-integral finite value, ceil signals inexact
*)
(# x,res: @Real;
enter x
exit res
#);
fmin: (* Returns the minimum of 2 reals *)
(# a,b: @real
enter (a,b)
do (if (a < b) then a->b if)
exit b
#);
fmax: (* Returns the maximum of 2 reals *)
(# a,b: @real
enter (a,b)
do (if (a < b) then b->a if)
exit a
#);
fabs: external
(* returns |x|, the absolute value of x *)
(# x,res: @Real;
enter x
exit res
#);
floor: external
(* largest integer value (in real format) not greater than x.
*
* If x is a NaN, floor returns a NaN.  If x is infinite, floor
* returns x. Invalid operation is signaled by floor if x is a NaN.
* If x is a non-integral finite value, floor signals inexact.
*)
(# x,res: @Real;
enter x
exit res
#);
fmod: external
(* Whenever possible, the fmod pattern returns the number f with
* the same sign as x, such that x = i*y + f for some integer i, and
* |f| < |y|. If y is 0, fmod returns a NaN.
*)
(# x,y,f: @Real;
enter (x,y)
exit f
#)
```

 13.10 Math Interface © 1990-2002 Mjølner Informatics [Modified: Monday August 24th 1998 at 14:43]