|
amath
1.8.5
Simple command line calculator
|
Real numbers math library. More...

Go to the source code of this file.
Macros | |
| #define | PI 3.1415926535897932384626433832795028841971693994 |
| #define | EULERS 2.7182818284590452353602874713526624977572470937 |
| #define | INFP 0x7FF0000000000000ull |
| #define | INFN 0xFFF0000000000000ull |
| #define | NAN 0x7FFFFFFFFFFFFFFFull |
| #define | sgn(x) (x > 0 ? 1 : x < 0 ? -1 : 0) |
| #define | abs(x) (x > 0 ? x : -x) |
Functions | |
| double | fabs (double x) |
| Returns the absolute value of x. More... | |
| double | ceil (double x) |
| Ceiling function. More... | |
| double | floor (double x) |
| Floor function. More... | |
| double | round (double x) |
| Round function. More... | |
| double | trunc (double x) |
| Truncate function. More... | |
| double | exp (double x) |
| Returns the exponential of x. More... | |
| double | sqrt (double x) |
| Square root function. More... | |
| double | cbrt (double x) |
| Cube root function. More... | |
| double | log (double x) |
| Natural logarithm function (base e) More... | |
| double | log10 (double x) |
| Base 10 logarithm function. More... | |
| double | cos (double x) |
| Cosine function. More... | |
| double | sin (double x) |
| Sine function. More... | |
| double | tan (double x) |
| Tangent function. More... | |
| double | sec (double x) |
| Secant function. More... | |
| double | csc (double x) |
| Cosecant function. More... | |
| double | cot (double x) |
| Cotangent function. More... | |
| double | exs (double x) |
| Exsecant function. More... | |
| double | exc (double x) |
| Excosecant function. More... | |
| double | crd (double x) |
| Chord function. More... | |
| double | acos (double x) |
| Inverse cosine function. More... | |
| double | asin (double x) |
| Inverse sine function. More... | |
| double | atan (double x) |
| Inverse tangent function. More... | |
| double | asec (double x) |
| Inverse secant function. More... | |
| double | acsc (double x) |
| Inverse cosecant function. More... | |
| double | acot (double x) |
| Inverse cotangent function. More... | |
| double | aexs (double x) |
| Inverse exsecant function. More... | |
| double | aexc (double x) |
| Inverse excosecant function. More... | |
| double | acrd (double x) |
| Inverse chord function. More... | |
| double | cosh (double x) |
| Hyperbolic cosine function. More... | |
| double | sinh (double x) |
| Hyperbolic sine function. More... | |
| double | tanh (double x) |
| Hyperbolic tangent function. More... | |
| double | sech (double x) |
| Hyperbolic secant function. More... | |
| double | csch (double x) |
| Hyperbolic cosecant function. More... | |
| double | coth (double x) |
| Hyperbolic cotangent function. More... | |
| double | acosh (double x) |
| Inverse hyperbolic cosine function. More... | |
| double | asinh (double x) |
| Inverse hyperbolic sine function. More... | |
| double | atanh (double x) |
| Inverse hyperbolic tangent function. More... | |
| double | asech (double x) |
| Inverse hyperbolic secant function. More... | |
| double | acsch (double x) |
| Inverse hyperbolic cosecant function. More... | |
| double | acoth (double x) |
| Inverse hyperbolic cotangent function. More... | |
| double | ver (double x) |
| Versed sine function. More... | |
| double | vcs (double x) |
| Versed cosine function. More... | |
| double | cvs (double x) |
| Coversed sine function. More... | |
| double | cvc (double x) |
| Coversed cosine function. More... | |
| double | hv (double x) |
| Haversed sine function. More... | |
| double | hvc (double x) |
| Haversed cosine function. More... | |
| double | hcv (double x) |
| Hacoversed sine function. More... | |
| double | hcc (double x) |
| Hacoversed cosine function. More... | |
| double | aver (double x) |
| Inverse versed sine function. More... | |
| double | avcs (double x) |
| Inverse versed sine. More... | |
| double | acvs (double x) |
| Inverse coversed sine function. More... | |
| double | acvc (double x) |
| Inverse versed cosine. More... | |
| double | ahv (double x) |
| Inverse haversed sine. More... | |
| double | ahvc (double x) |
| Inverse haversed cosine. More... | |
| double | ahcv (double x) |
| Inverse hacoversed sine. More... | |
| double | ahcc (double x) |
| Inverse hacoversed cosine. More... | |
| double | pow (double x, double y) |
| Expontation function. More... | |
| double | fmod (double x, double y) |
| Return x mod y in exact arithmetic. More... | |
| double | atan2 (double y, double x) |
| Inverse tangent function. More... | |
| double | hypot (double x, double y) |
| hypot More... | |
| double | log2p (double x, double y) |
| double | log1p (double x) |
| double | expm1 (double x) |
| double | scalbn (double x, int n) |
| double | copysign (double x, double y) |
| Returns a value with the magnitude of x and with the sign bit of y. More... | |
| int | rempio2 (double x, double *y) |
| unsigned int | log2i (unsigned int x) |
Real numbers math library.
The library is based on fdlib by Sun Microsystems.
The original library can be downloaded at netlib.org:
http://www.netlib.org/fdlibm/
or from mirror site hensa.ac.uk:
http://www.hensa.ac.uk/
More info on double precision floating point at Wikipedia:
https://wikipedia.org/wiki/Double-precision_floating-point_format
Definition in file mathr.h.
| #define EULERS 2.7182818284590452353602874713526624977572470937 |
| double acos | ( | double | x | ) |
Inverse cosine function.
Method
acos(x) = pi/2 - asin(x)
acos(-x) = pi/2 + asin(x) For |x|<=0.5
acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) For x>0.5
acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
= 2asin(sqrt((1-x)/2))
= 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
= 2f + (2c + 2s*z*R(z))
where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
for f so that f+c ~ sqrt(z). For x<-0.5
acos(x) = pi - 2asin(sqrt((1-|x|)/2))
= pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)Special cases
if x is NaN, return NaN
if |x|>1, return NaN
Definition at line 92 of file acos.c.
References one, pi, pio2_hi, pio2_lo, pS0, pS1, pS2, pS3, pS4, pS5, qS1, qS2, qS3, qS4, and sqrt().
Referenced by ahvc(), RealNumber::ArcCosine(), asec(), and avcs().


| double acosh | ( | double | x | ) |
Inverse hyperbolic cosine function.
Based on
acosh(x) = log [ x + sqrt(x*x-1) ]we have
acosh(x) = log(x)+ln2, if x is large; else
acosh(x) = log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
acosh(x) = log1p(t+sqrt(2.0*t+t*t)); where t=x-1Special cases
acosh(x) is NaN if x<1
acosh(NaN) is NaN
Definition at line 69 of file acosh.c.
References ln2, log(), log1p(), one, and sqrt().
Referenced by RealNumber::HypArcCosine().


| double acot | ( | double | x | ) |
Inverse cotangent function.
Method
arccot(x) = arctan(1/x)
Definition at line 45 of file acot.c.
References atan().
Referenced by RealNumber::ArcCotangent().


| double acoth | ( | double | x | ) |
Inverse hyperbolic cotangent function.
Method
x + 1
acoth(x) = 0.5 * ln( ----— )
x - 1
when x in [-1, 1]
acoth(x) = NaN
Definition at line 49 of file acoth.c.
References log().
Referenced by RealNumber::HypArcCotangent().


| double acrd | ( | double | x | ) |
Inverse chord function.
Method
arccrd(x) = 2*arcsin(x/2)
Definition at line 45 of file acrd.c.
References asin().
Referenced by RealNumber::ArcChord().


| double acsc | ( | double | x | ) |
Inverse cosecant function.
Method
arccsc(x) = arcsin(1/x)
Definition at line 45 of file acsc.c.
References asin().
Referenced by RealNumber::ArcCosecant().


| double acsch | ( | double | x | ) |
Inverse hyperbolic cosecant function.
Method
1+sqrt(1+x*x)
acsch(x) = ln( ------------— )
x
when x is 0
acsch(x) = NaN
Definition at line 49 of file acsch.c.
Referenced by RealNumber::HypArcCosecant().


| double acvc | ( | double | x | ) |
Inverse versed cosine.
Method
acvc(x) = asin(1+x)
Definition at line 45 of file acvc.c.
References asin().
Referenced by RealNumber::ArcCoVerCosine().


| double acvs | ( | double | x | ) |
Inverse coversed sine function.
Definition at line 40 of file acvs.c.
References atan(), and sqrt().
Referenced by RealNumber::ArcCoVerSine().


| double aexc | ( | double | x | ) |
Inverse excosecant function.
Method
aexcsc(x) = arccsc(x+1)
= arcsin(1/(x+1))
Definition at line 46 of file aexc.c.
References asin().
Referenced by RealNumber::ArcExCosecant().


| double aexs | ( | double | x | ) |
Inverse exsecant function.
Method
aexsec(x) = arcsec(x+1)
= arccos(1/(x+1))
= arctan(sqrt(x^2+2*X))
Definition at line 47 of file aexs.c.
References atan(), and sqrt().
Referenced by RealNumber::ArcExSecant().


| double ahcc | ( | double | x | ) |
Inverse hacoversed cosine.
Definition at line 40 of file ahcc.c.
Referenced by RealNumber::ArcHaCoVerCosine().

| double ahcv | ( | double | x | ) |
Inverse hacoversed sine.
Definition at line 40 of file ahcv.c.
Referenced by RealNumber::ArcHaCoVerSine().

| double ahv | ( | double | x | ) |
Inverse haversed sine.
Definition at line 40 of file ahv.c.
References atan(), and sqrt().
Referenced by RealNumber::ArcHaVerSine().


| double ahvc | ( | double | x | ) |
Inverse haversed cosine.
Definition at line 40 of file ahvc.c.
References acos(), and sqrt().
Referenced by RealNumber::ArcHaVerCosine().


| double asec | ( | double | x | ) |
Inverse secant function.
Method
arcsec(x) = arccos(1/x)
Definition at line 45 of file asec.c.
References acos().
Referenced by RealNumber::ArcSecant().


| double asech | ( | double | x | ) |
Inverse hyperbolic secant function.
Method
1+sqrt(1-x*x)
asech(x) = ln( ------------— )
x
when x <= 0
asech(x) = NaN when x > 1
asech(x) = NaN
Definition at line 52 of file asech.c.
Referenced by RealNumber::HypArcSecant().


| double asin | ( | double | x | ) |
Inverse sine function.
Method
Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
we approximate asin(x) on [0,0.5] by
asin(x) = x + x*x^2*R(x^2)
where
R(x^2) is a rational approximation of (asin(x)-x)/x^3
and its remez error is bounded by
|(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)For x in [0.5,1]
asin(x) = pi/2-2*asin(sqrt((1-x)/2))
Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
then for x>0.98
asin(x) = pi/2 - 2*(s+s*z*R(z))
= pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)For x<=0.98, let pio4_hi = pio2_hi/2, then
f = hi part of s;
c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
and
asin(x) = pi/2 - 2*(s+s*z*R(z))
= pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
= pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))Special cases
if x is NaN, return NaN
if |x|>1, return NaN
Definition at line 100 of file asin.c.
References fabs(), huge, one, pio2_hi, pio2_lo, pio4_hi, pS0, pS1, pS2, pS3, pS4, pS5, qS1, qS2, qS3, qS4, and sqrt().
Referenced by acrd(), acsc(), acvc(), aexc(), and RealNumber::ArcSine().


| double asinh | ( | double | x | ) |
Inverse hyperbolic sine function.
Method
Based on
asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] we have
asinh(x) = x if 1+x*x=1,
= sign(x)*(log(x)+ln2)) for large |x|, else
= sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
= sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
Definition at line 68 of file asinh.c.
References fabs(), huge, ln2, log(), log1p(), one, and sqrt().
Referenced by RealNumber::HypArcSine().


| double atan | ( | double | x | ) |
Inverse tangent function.
Method
1. Reduce x to positive by atan(x) = -atan(-x).
2. According to the integer k=4t+0.25 chopped, t=x, the argument
is further reduced to one of the following intervals and the
arctangent of t is evaluated by the corresponding formula: [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
[7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
[11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
[19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
[39/16,INF] atan(x) = atan(INF) + atan( -1/t )Constants
The hexadecimal values are the intended ones for the following
constants. The decimal values may be used, provided that the
compiler will convert from decimal to binary accurately enough
to produce the hexadecimal values shown.
Definition at line 103 of file atan.c.
References aT, atanhi, atanlo, fabs(), huge, and one.
Referenced by acot(), acvs(), aexs(), ahv(), RealNumber::ArcTangent(), atan2(), and aver().


| double atan2 | ( | double | y, |
| double | x | ||
| ) |
Inverse tangent function.
| y,x |
Method
1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
2. Reduce x to positive by (if x and y are unexceptional):
ARG (x+iy) = arctan(y/x) ... if x > 0,
ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,Special cases
ATAN2((anything), NaN ) is NaN;
ATAN2(NAN , (anything) ) is NaN;
ATAN2(+-0, +(anything but NaN)) is +-0 ;
ATAN2(+-0, -(anything but NaN)) is +-pi ;
ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
ATAN2(+-INF,+INF ) is +-pi/4 ;
ATAN2(+-INF,-INF ) is +-3pi/4;
ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;Constants
The hexadecimal values are the intended ones for the following
constants. The decimal values may be used, provided that the
compiler will convert from decimal to binary accurately enough
to produce the hexadecimal values shown.
Definition at line 87 of file atan2.c.
References atan(), fabs(), pi, pi_lo, pi_o_2, pi_o_4, tiny, and zero.
Referenced by clog(), and cpow().


| double atanh | ( | double | x | ) |
Inverse hyperbolic tangent function.
Method
1.Reduced x to positive by atanh(-x) = -atanh(x)
2.For x>=0.5
1 2x x
atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
2 1 - x 1 - x
For x<0.5
atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
Special cases
atanh(x) is NaN if |x| > 1
atanh(NaN) is that NaN
atanh(+-1) is +-INF
Definition at line 72 of file atanh.c.
References huge, log1p(), one, and zero.
Referenced by RealNumber::HypArcTangent().


| double avcs | ( | double | x | ) |
Inverse versed sine.
avcs(x) = acos(1+x)
Definition at line 44 of file avcs.c.
References acos().
Referenced by RealNumber::ArcVerCosine().


| double aver | ( | double | x | ) |
Inverse versed sine function.
Definition at line 40 of file aver.c.
References atan(), and sqrt().
Referenced by RealNumber::ArcVerSine().


| double cbrt | ( | double | x | ) |
Cube root function.
Definition at line 62 of file cbrt.c.
References B1, B2, C, D, E, F, and G.
Referenced by RealNumber::CubeRoot().

| double ceil | ( | double | x | ) |
Ceiling function.
| x |
Method
Bit twiddlingException
Inexact flag raised if x not equal to ceil(x).
Definition at line 63 of file ceil.c.
References huge.
Referenced by cceil(), RealNumber::Ceiling(), Dragon4(), round(), and trunc().

| double copysign | ( | double | x, |
| double | y | ||
| ) |
Returns a value with the magnitude of x and with the sign bit of y.
Definition at line 47 of file csign.c.
Referenced by scalbn().

| double cos | ( | double | x | ) |
Cosine function.
| x |
Kernel function:__kernel_sin ... sine function on [-pi/4,pi/4] __kernel_cos ... cose function on [-pi/4,pi/4] __ieee754_rem_pio2 ... argument reduction routine
Method:
Let S,C and T denote the sin, cos and tan respectively on
[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
in [-pi/4 , +pi/4], and let n = k mod 4.
We have
n sin(x) cos(x) tan(x)
----------------------------------------------------------
0 S C T
1 C -S -1/T
2 -S -C T
3 -C S -1/T
----------------------------------------------------------
Special cases:Let trig be any of sin, cos, or tan. trig(+-INF) is NaN trig(NaN) is that NaN
Accuracy:TRIG(x) returns trig(x) nearly rounded
Definition at line 87 of file cos.c.
References __kernel_cos(), __kernel_sin(), and rempio2().
Referenced by cchc(), ccos(), ccosh(), ccot(), ccoth(), ccsc(), ccsch(), cexp(), RealNumber::Cosine(), cot(), cpow(), csc(), csec(), csech(), csin(), csinh(), ctan(), ctanh(), hv(), hvc(), sec(), and vcs().


| double cosh | ( | double | x | ) |
Hyperbolic cosine function.
Mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
Method
1. Replace x by |x| (cosh(x) = cosh(-x))
2.
[ exp(x) - 1 ]^2
0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
2*exp(x)
exp(x) + 1/exp(x)
ln2/2 <= x <= 22 : cosh(x) := -------------------
2
22 <= x <= lnovft : cosh(x) := exp(x)/2
lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
ln2ovft < x : cosh(x) := huge*huge (overflow)
Special cases:cosh(x) is |x| if x is +INF, -INF, or NaN only cosh(0)=1 is exact for finite x
Definition at line 83 of file cosh.c.
References exp(), expm1(), fabs(), half, huge, and one.
Referenced by cchc(), cchsh(), ccot(), ccoth(), ccsc(), ccsch(), coth(), csec(), csech(), ctan(), ctanh(), RealNumber::HypCosine(), and sech().


| double cot | ( | double | x | ) |
Cotangent function.
| x |
cot(x) = 1/tan(x)
= cos(x)/sin(x)
= sin(2*x)/(cos(2*x)-1)
Definition at line 47 of file cot.c.
Referenced by RealNumber::Cotangent().


| double coth | ( | double | x | ) |
Hyperbolic cotangent function.
coth(x) = cosh(x)/sinh(x)
Definition at line 44 of file coth.c.
References cosh(), and sinh().
Referenced by RealNumber::HypCotangent().


| double crd | ( | double | x | ) |
Chord function.
crd(x) = 2*sin(x/2)
Definition at line 44 of file crd.c.
References sin().
Referenced by RealNumber::Chord().


| double csc | ( | double | x | ) |
Cosecant function.
csc = sin(1/x)
= -2*sin(x)/(cos(2*x) - 1)
Definition at line 45 of file csc.c.
Referenced by RealNumber::Cosecant(), and exc().


| double csch | ( | double | x | ) |
Hyperbolic cosecant function.
csch(x) = 1/sinh(x)
Definition at line 44 of file csch.c.
References sinh().
Referenced by RealNumber::HypCosecant().


| double cvc | ( | double | x | ) |
Coversed cosine function.
cvc(x) = 1+sin(x)
Definition at line 44 of file cvc.c.
References sin().
Referenced by RealNumber::CoVerCosine().


| double cvs | ( | double | x | ) |
Coversed sine function.
cvs(x) = 1-sin(x)
Definition at line 44 of file cvs.c.
References sin().
Referenced by RealNumber::CoVerSine(), and exc().


| double exc | ( | double | x | ) |
Excosecant function.
excsc(x) = csc(x)-1
= (1-sin(x))/sin(x)
= cvs(x)/sin(x)
= cvs(x)*csc(x)
Definition at line 47 of file exc.c.
Referenced by RealNumber::ExCosecant().


| double exp | ( | double | x | ) |
Returns the exponential of x.
Method
1. Argument reduction:
Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
Given x, find r and integer k such that
x = k*ln2 + r, |r| <= 0.5*ln2.
Here r will be represented as r = hi-lo for better
accuracy.
2. Approximation of exp(r) by a special rational function on
the interval [0,0.34658]:
Write
R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
We use a special Remes algorithm on [0,0.34658] to generate
a polynomial of degree 5 to approximate R. The maximum error
of this polynomial approximation is bounded by 2**-59. In
other words,
R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
(where z=r*r, and the values of P1 to P5 are listed below)
and
| 5 | -59
| 2.0+P1*z+...+P5*z - R(z) | <= 2
| |
The computation of exp(r) thus becomes
2*r
exp(r) = 1 + -------
R - r
r*R1(r)
= 1 + r + ----------- (for better accuracy)
2 - R1(r)
where
2 4 10
R1(r) = r - (P1*r + P2*r + ... + P5*r ).
3. Scale back to obtain exp(x):
From step 1, we have
exp(x) = 2^k * exp(r)
Special cases:exp(INF) is INF, exp(NaN) is NaN; exp(-INF) is 0, and for finite argument, only exp(0)=1 is exact.
Accuracy:according to an error analysis, the error is always less than 1 ulp (unit in the last place).
Misc. info:
For IEEE double
if x > 7.09782712893383973096e+02 then exp(x) overflow
if x < -7.45133219101941108420e+02 then exp(x) underflow
Constants:
The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown.
Definition at line 138 of file exp.c.
References halF, huge, invln2, ln2HI, ln2LO, o_threshold, one, P1, P2, P3, P4, P5, twom1000, and u_threshold.
Referenced by cchsh(), cexp(), cosh(), cpow(), and sinh().

| double expm1 | ( | double | x | ) |
Definition at line 153 of file expm1.c.
References huge, invln2, ln2_hi, ln2_lo, o_threshold, one, Q1, Q2, Q3, Q4, Q5, and tiny.
Referenced by cosh(), sinh(), and tanh().

| double exs | ( | double | x | ) |
Exsecant function.
exsec(x) = sec(x)-1
= (1-cos(x))/cos(x)
= ver(x)/cos(x)
= ver(x)*sec(x)
= 2*sin(x/2)*sin(x/2)*sec(x)
Definition at line 48 of file exs.c.
Referenced by RealNumber::ExSecant().


| double fabs | ( | double | x | ) |
Returns the absolute value of x.
Definition at line 51 of file fabs.c.
Referenced by __kernel_tan(), RealNumber::Absolute(), asin(), asinh(), atan(), atan2(), cchsh(), cosh(), csqrt(), DecimalSystem::GetText(), PositionalNumeralSystem::GetText(), pow(), rempio2(), sinh(), and tanh().

| double floor | ( | double | x | ) |
Floor function.
Method:
Bit twiddlingException:
Inexact flag raised if x not equal to floor(x)
Definition at line 62 of file floor.c.
References huge.
Referenced by __kernel_rem_pio2(), cfloor(), RealNumber::Floor(), round(), and trunc().

| double fmod | ( | double | x, |
| double | y | ||
| ) |
Return x mod y in exact arithmetic.
Method: Shift and subtract
Definition at line 58 of file fmod.c.
Referenced by PositionalNumeralSystem::IntegerToBuffer().

| double hcc | ( | double | x | ) |
Hacoversed cosine function.
hcc(x) = (1+sin(x))/2
Definition at line 44 of file hcc.c.
References sin().
Referenced by RealNumber::HaCoVerCosine().


| double hcv | ( | double | x | ) |
Hacoversed sine function.
hcv(x) = (1-sin(x))/2
Definition at line 44 of file hcv.c.
References sin().
Referenced by RealNumber::HaCoVerSine().


| double hv | ( | double | x | ) |
Haversed sine function.
hv(x) = (1-cos(x))/2
Definition at line 44 of file hv.c.
References cos().
Referenced by RealNumber::HaVerSine().


| double hvc | ( | double | x | ) |
Haversed cosine function.
hvc(x) = (1+cos(x))/2
Definition at line 44 of file hvc.c.
References cos().
Referenced by RealNumber::HaVerCosine().


| double hypot | ( | double | x, |
| double | y | ||
| ) |
hypot
Method If (assume round-to-nearest) z=x*x+y*y has error less than sqrt(2)/2 ulp, than sqrt(z) has error less than 1 ulp (exercise).
So, compute sqrt(x*x+y*y) with some care as follows to get the error below 1 ulp:
Assume x>y>0;
(if possible, set rounding to round-to-nearest)
1. if x > 2y use
x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y
where x1 = x with lower 32 bits cleared, x2 = x-x1; else
2. if x <= 2y use
t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1,
y1= y with lower 32 bits chopped, y2 = y-y1. NOTE: scaling may be necessary if some argument is too
large or too tinySpecial cases: hypot(x,y) is INF if x or y is +INF or -INF; else hypot(x,y) is NAN if x or y is NAN.
Accuracy:
hypot(x,y) returns sqrt(x^2+y^2) with error less
than 1 ulps (units in the last place)
Definition at line 81 of file hypot.c.
References sqrt().
Referenced by cabs().


| double log | ( | double | x | ) |
Natural logarithm function (base e)
Method
1. Argument Reduction: find k and f such that
x = 2^k * (1+f),
where sqrt(2)/2 < 1+f < sqrt(2) . 2. Approximation of log(1+f).
Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
= 2s + 2/3 s**3 + 2/5 s**5 + .....,
= 2s + s*R
We use a special Remes algorithm on [0,0.1716] to generate
a polynomial of degree 14 to approximate R The maximum error
of this polynomial approximation is bounded by 2**-58.45. In
other words,
2 4 6 8 10 12 14
R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
(the values of Lg1 to Lg7 are listed in the program)
and
| 2 14 | -58.45
| Lg1*s +...+Lg7*s - R(z) | <= 2
| |
Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
In order to guarantee error in log below 1ulp, we compute log
by
log(1+f) = f - s*(f - R) (if f is not too large)
log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy) 3. Finally, log(x) = k*ln2 + log(1+f).
= k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
Here ln2 is split into two floating point number:
ln2_hi + ln2_lo,
where n*ln2_hi is always exact for |n| < 2000.Special cases: log(x) is NaN with signal if x < 0 (including -INF) ; log(+INF) is +INF; log(0) is -INF with signal; log(NaN) is that NaN with no signal.
Accuracy: according to an error analysis, the error is always less than 1 ulp (unit in the last place).
Constants: The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown.
Definition at line 109 of file log.c.
References Lg1, Lg2, Lg3, Lg4, Lg5, Lg6, Lg7, ln2_hi, ln2_lo, two54, and zero.
Referenced by acosh(), acoth(), acsch(), asech(), asinh(), clog(), cpow(), RealNumber::Log(), log10(), RealNumber::Log2(), and log2p().

| double log10 | ( | double | x | ) |
Base 10 logarithm function.
Method:
Let log10_2hi = leading 40 bits of log10(2) and
log10_2lo = log10(2) - log10_2hi,
ivln10 = 1/log(10) rounded.
Then
n = ilogb(x),
if(n<0) n = n+1;
x = scalbn(x,-n);
log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
Note 1:
To guarantee log10(10**n)=n, where 10**n is normal, the rounding
mode must set to Round-to-Nearest.
Note 2:
[1/log(10)] rounded to 53 bits has error .198 ulps;
log10 is monotonic at all binary break points.
Special cases:log10(x) is NaN with signal if x < 0; log10(+INF) is +INF with no signal; log10(0) is -INF with signal; log10(NaN) is that NaN with no signal; log10(10**N) = N for N=0,1,...,22.
Constants: The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown.
Definition at line 93 of file log10.c.
References ivln10, log(), log10_2hi, log10_2lo, two54, and zero.
Referenced by DecimalSystem::GetText(), and RealNumber::Log10().


| double log1p | ( | double | x | ) |
Definition at line 122 of file log1p.c.
References ln2_hi, ln2_lo, Lp1, Lp2, Lp3, Lp4, Lp5, Lp6, Lp7, two54, and zero.
Referenced by acosh(), asinh(), and atanh().

| unsigned int log2i | ( | unsigned int | x | ) |
| double log2p | ( | double | x, |
| double | y | ||
| ) |
Definition at line 32 of file log2p.c.
References log().
Referenced by PositionalNumeralSystem::GetText().


| double pow | ( | double | x, |
| double | y | ||
| ) |
Expontation function.
Method: Let x = 2 * (1+f)
1. Compute and return log2(x) in two pieces:
log2(x) = w1 + w2,
where w1 has 53-24 = 29 bit trailing zeros.
2. Perform y*log2(x) = n+y' by simulating muti-precision
arithmetic, where |y'|<=0.5.
3. Return x**y = 2**n*exp(y'*log2)Special cases: 1. (anything) ** 0 is 1 2. (anything) ** 1 is itself 3. (anything) ** NAN is NAN 4. NAN ** (anything except 0) is NAN 5. +-(|x| > 1) ** +INF is +INF 6. +-(|x| > 1) ** -INF is +0 7. +-(|x| < 1) ** +INF is +0 8. +-(|x| < 1) ** -INF is +INF 9. +-1 ** +-INF is NAN 10. +0 ** (+anything except 0, NAN) is +0 11. -0 ** (+anything except 0, NAN, odd integer) is +0 12. +0 ** (-anything except 0, NAN) is +INF 13. -0 ** (-anything except 0, NAN, odd integer) is +INF 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) 15. +INF ** (+anything except 0,NAN) is +INF 16. +INF ** (-anything except 0,NAN) is +0 17. -INF ** (anything) = -0 ** (-anything) 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) 19. (-anything except 0 and inf) ** (non-integer) is NAN
Accuracy:
pow(x,y) returns x**y nearly rounded. In particular
pow(integer,integer)
always returns the correct integer provided it is
representable.Constants : The hexadecimal values are the intended ones for the following constants. The decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the hexadecimal values shown.
Definition at line 138 of file pow.c.
References bp, cp, cp_h, cp_l, dp_h, dp_l, fabs(), huge, ivln2, ivln2_h, ivln2_l, L1, L2, L3, L4, L5, L6, lg2, lg2_h, lg2_l, one, ovt, P1, P2, P3, P4, P5, scalbn(), sqrt(), tiny, two, two53, and zero.
Referenced by cpow(), PositionalNumeralSystem::GetText(), PositionalNumeralSystem::Parse(), and RealNumber::Raise().


| int rempio2 | ( | double | x, |
| double * | y | ||
| ) |
Definition at line 104 of file remp2.c.
References __kernel_rem_pio2(), fabs(), half, invpio2, npio2_hw, pio2_1, pio2_1t, pio2_2, pio2_2t, pio2_3, pio2_3t, two24, two_over_pi, and zero.
Referenced by cos(), sin(), and tan().


| double round | ( | double | x | ) |
Round function.
Definition at line 40 of file round.c.
References ceil(), and floor().
Referenced by cround(), PositionalNumeralSystem::GetText(), and RealNumber::Round().


| double scalbn | ( | double | x, |
| int | n | ||
| ) |
| double sec | ( | double | x | ) |
Secant function.
sec(x) = 1/cos(x)
= 1/sqrt(cos(x)*cos(x))
Definition at line 45 of file sec.c.
Referenced by exs(), and RealNumber::Secant().


| double sech | ( | double | x | ) |
Hyperbolic secant function.
sech(x) = 1/cosh(x)
Definition at line 44 of file sech.c.
References cosh().
Referenced by RealNumber::HypSecant().


| double sin | ( | double | x | ) |
Sine function.
Kernel function:__kernel_sin ... sine function on [-pi/4,pi/4] __kernel_cos ... cose function on [-pi/4,pi/4] __ieee754_rem_pio2 ... argument reduction routine
Method:
Let S,C and T denote the sin, cos and tan respectively on
[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
in [-pi/4 , +pi/4], and let n = k mod 4.
We have
n sin(x) cos(x) tan(x)
----------------------------------------------------------
0 S C T
1 C -S -1/T
2 -S -C T
3 -C S -1/T
----------------------------------------------------------
Special cases:Let trig be any of sin, cos, or tan. trig(+-INF) is NaN trig(NaN) is that NaN
Accuracy:TRIG(x) returns trig(x) nearly rounded
Definition at line 86 of file sin.c.
References __kernel_cos(), __kernel_sin(), and rempio2().
Referenced by ccos(), ccosh(), ccot(), ccoth(), ccsc(), ccsch(), cexp(), cot(), cpow(), crd(), csc(), csec(), csech(), csin(), csinh(), ctan(), ctanh(), cvc(), cvs(), hcc(), hcv(), RealNumber::Sine(), and ver().


| double sinh | ( | double | x | ) |
Hyperbolic sine function.
Method
mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
1. Replace x by |x| (sinh(-x) = -sinh(x)).
2.
E + E/(E+1)
0 <= x <= 22 : sinh(x) := -----------—, E=expm1(x)
2 22 <= x <= lnovft : sinh(x) := exp(x)/2
lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
ln2ovft < x : sinh(x) := x*shuge (overflow)Special cases
sinh(x) is |x| if x is +INF, -INF, or NaN.
only sinh(0)=0 is exact for finite x.
Definition at line 77 of file sinh.c.
References exp(), expm1(), fabs(), one, and shuge.
Referenced by cchsh(), ccot(), ccoth(), ccsc(), ccsch(), coth(), csch(), csec(), csech(), ctan(), ctanh(), and RealNumber::HypSine().


| double sqrt | ( | double | x | ) |
Square root function.
Method:
Bit by bit method using integer arithmetic. (Slow, but portable)
1. Normalization
Scale x to y in [1,4) with even powers of 2:
find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
sqrt(x) = 2^k * sqrt(y)
2. Bit by bit computation
Let q = sqrt(y) truncated to i bit after binary point (q = 1),
i 0
i+1 2
s = 2*q , and y = 2 * ( y - q ). (1)
i i i i To compute q from q , one checks whether
i+1 i
-(i+1) 2
(q + 2 ) <= y. (2)
i
-(i+1)
If (2) is false, then q = q ; otherwise q = q + 2 .
i+1 i i+1 i With some algebric manipulation, it is not difficult to see
that (2) is equivalent to
-(i+1)
s + 2 <= y (3)
i i The advantage of (3) is that s and y can be computed by
i i
the following recurrence formula:
if (3) is false s = s , y = y ; (4)
i+1 i i+1 i otherwise,
-i -(i+1)
s = s + 2 , y = y - s - 2 (5)
i+1 i i+1 i i One may easily use induction to prove (4) and (5).
Note. Since the left hand side of (3) contain only i+2 bits,
it does not necessary to do a full (53-bit) comparison
in (3).
3. Final rounding
After generating the 53 bits result, we compute one more bit.
Together with the remainder, we can decide whether the
result is exact, bigger than 1/2ulp, or less than 1/2ulp
(it will never equal to 1/2ulp).
The rounding mode can be detected by checking whether
huge + tiny is equal to huge, and whether huge - tiny is
equal to huge for some floating point number "huge" and "tiny".Special cases: sqrt(+-0) = +-0 ... exact sqrt(inf) = inf sqrt(-ve) = NaN ... with invalid signal sqrt(NaN) = NaN ... with invalid signal for signaling NaN
Definition at line 119 of file sqrt.c.
Referenced by acos(), acosh(), acsch(), acvs(), aexs(), ahv(), ahvc(), asech(), asin(), asinh(), aver(), csqrt(), hypot(), pow(), sec(), and RealNumber::SquareRoot().

| double tan | ( | double | x | ) |
Tangent function.
Kernel function:__kernel_sin ... sine function on [-pi/4,pi/4] __kernel_cos ... cose function on [-pi/4,pi/4] __ieee754_rem_pio2 ... argument reduction routine
Method:
Let S,C and T denote the sin, cos and tan respectively on
[-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
in [-pi/4 , +pi/4], and let n = k mod 4.
We have
n sin(x) cos(x) tan(x)
----------------------------------------------------------
0 S C T
1 C -S -1/T
2 -S -C T
3 -C S -1/T
----------------------------------------------------------
Special cases:Let trig be any of sin, cos, or tan. trig(+-INF) is NaN trig(NaN) is that NaN
Accuracy:TRIG(x) returns trig(x) nearly rounded
Definition at line 87 of file tan.c.
References __kernel_tan(), and rempio2().
Referenced by RealNumber::Tangent().


| double tanh | ( | double | x | ) |
Hyperbolic tangent function.
Method
x -x
e - e
0. tanh(x) is defined to be --------—
x -x
e + e1. reduce x to non-negative by tanh(-x) = -tanh(x)
2. 0 <= x <= 2**-55 : tanh(x) = x*(one+x)
-t
2**-55 < x <= 1 : tanh(x) = --—; t = expm1(-2x)
t + 2
2
1 <= x <= 22.0 : tanh(x) = 1- --— ; t=expm1(2x)
t + 2
22.0 < x <= INF : tanh(x) = 1Special cases
tanh(NaN) is NaN
only tanh(0)=0 is exact for finite argument.
Definition at line 81 of file tanh.c.
References expm1(), fabs(), one, tiny, and two.
Referenced by RealNumber::HypTangent().


| double trunc | ( | double | x | ) |
Truncate function.
when x > 0 trunc(0) = floor(x)
when x < 0 trunc(x) = ceil(x)
Special case trunc(0) = 0 trunc(NaN) = NaN
Definition at line 52 of file trunc.c.
References ceil(), and floor().
Referenced by ctrunc(), DecimalSystem::GetText(), PositionalNumeralSystem::GetText(), PositionalNumeralSystem::IntegerToBuffer(), and RealNumber::Trunc().


| double vcs | ( | double | x | ) |
Versed cosine function.
vercos = 1+cos(x)
= 2*cos(x/2)*cos(x/2)
Definition at line 45 of file vcs.c.
References cos().
Referenced by RealNumber::VerCosine().


| double ver | ( | double | x | ) |
Versed sine function.
versin = 1-cos(x)
= 2*sin(x/2)*sin(x/2)
Definition at line 45 of file ver.c.
References sin().
Referenced by exs(), and RealNumber::VerSine().

