diff --git a/std/math.d b/std/math.d index 6b77bb3af..93c4e51e0 100644 --- a/std/math.d +++ b/std/math.d @@ -1,4 +1,4 @@ -// math.d +// Written in the D programming language /** * Macros: @@ -18,6 +18,11 @@ * POWER = $1$2 * BIGSUM = $(BIG Σ $2$(SMALL $1)) * CHOOSE = $(BIG () $(SMALL $1)$(SMALL $2) $(BIG )) + * PLUSMN = ± + * INFIN = ∞ + * PI = π + * LT = < + * GT = > */ /* @@ -63,7 +68,7 @@ private import std.c.math; class NotImplemented : Error { - this(char[] msg) + this(string msg) { super(msg ~ "not implemented"); } @@ -76,14 +81,14 @@ const real LOG2 = 0x1.34413509f79fef32p-2; /** log102 */ // 0.30103 f const real LOG10E = 0.43429448190325182765; /** log10e */ const real LN2 = 0x1.62e42fefa39ef358p-1; /** ln 2 */ // 0.693147 fldln2 const real LN10 = 2.30258509299404568402; /** ln 10 */ -const real PI = 0x1.921fb54442d1846ap+1; /** π */ // 3.14159 fldpi -const real PI_2 = 1.57079632679489661923; /** π / 2 */ -const real PI_4 = 0.78539816339744830962; /** π / 4 */ -const real M_1_PI = 0.31830988618379067154; /** 1 / π */ -const real M_2_PI = 0.63661977236758134308; /** 2 / π */ -const real M_2_SQRTPI = 1.12837916709551257390; /** 2 / √π */ +const real PI = 0x1.921fb54442d1846ap+1; /** $(PI) */ // 3.14159 fldpi +const real PI_2 = 1.57079632679489661923; /** $(PI) / 2 */ +const real PI_4 = 0.78539816339744830962; /** $(PI) / 4 */ +const real M_1_PI = 0.31830988618379067154; /** 1 / $(PI) */ +const real M_2_PI = 0.63661977236758134308; /** 2 / $(PI) */ +const real M_2_SQRTPI = 1.12837916709551257390; /** 2 / √$(PI) */ const real SQRT2 = 1.41421356237309504880; /** √2 */ -const real SQRT1_2 = 0.70710678118654752440; /** √½ */ +const real SQRT1_2 = 0.70710678118654752440; /** √½ */ /* Octal versions: @@ -178,9 +183,9 @@ unittest * Returns cosine of x. x is in radians. * * $(TABLE_SV - * $(TR $(TH x) $(TH cos(x)) $(TH invalid?) ) - * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes) ) - * $(TR $(TD ±∞) $(TD $(NAN)) $(TD yes) ) + * $(TR $(TH x) $(TH cos(x)) $(TH invalid?)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD yes) ) * ) * Bugs: * Results are undefined if |x| >= $(POWER 2,64). @@ -192,10 +197,10 @@ real cos(real x); /* intrinsic */ * Returns sine of x. x is in radians. * * $(TABLE_SV - * x sin(x) invalid? - * $(NAN) $(NAN) yes - * ±0.0 ±0.0 no - * ±∞ $(NAN) yes + * $(TR $(TH x) $(TH sin(x)) $(TH invalid?)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD yes)) * ) * Bugs: * Results are undefined if |x| >= $(POWER 2,64). @@ -208,10 +213,10 @@ real sin(real x); /* intrinsic */ * Returns tangent of x. x is in radians. * * $(TABLE_SV - * x tan(x) invalid? - * $(NAN) $(NAN) yes - * ±0.0 ±0.0 no - * ±∞ $(NAN) yes + * $(TR $(TH x) $(TH tan(x)) $(TH invalid?)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD yes)) * ) */ @@ -307,61 +312,61 @@ unittest /*************** * Calculates the arc cosine of x, - * returning a value ranging from -π/2 to π/2. + * returning a value ranging from -$(PI)/2 to $(PI)/2. * * $(TABLE_SV - * x acos(x) invalid? - * >1.0 $(NAN) yes - * <-1.0 $(NAN) yes - * $(NAN) $(NAN) yes + * $(TR $(TH x) $(TH acos(x)) $(TH invalid?)) + * $(TR $(TD $(GT)1.0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(LT)-1.0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes)) * ) */ real acos(real x) { return std.c.math.acosl(x); } /*************** * Calculates the arc sine of x, - * returning a value ranging from -π/2 to π/2. + * returning a value ranging from -$(PI)/2 to $(PI)/2. * * $(TABLE_SV - * x asin(x) invalid? - * ±0.0 ±0.0 no - * >1.0 $(NAN) yes - * <-1.0 $(NAN) yes + * $(TR $(TH x) $(TH asin(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(GT)1.0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(LT)-1.0) $(TD $(NAN)) $(TD yes)) * ) */ real asin(real x) { return std.c.math.asinl(x); } /*************** * Calculates the arc tangent of x, - * returning a value ranging from -π/2 to π/2. + * returning a value ranging from -$(PI)/2 to $(PI)/2. * * $(TABLE_SV - * x atan(x) invalid? - * ±0.0 ±0.0 no - * ±∞ $(NAN) yes + * $(TR $(TH x) $(TH atan(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD yes)) * ) */ real atan(real x) { return std.c.math.atanl(x); } /*************** * Calculates the arc tangent of y / x, - * returning a value ranging from -π/2 to π/2. + * returning a value ranging from -$(PI)/2 to $(PI)/2. * * $(TABLE_SV - * y x atan(y, x) - * $(NAN) anything $(NAN) - * anything $(NAN) $(NAN) - * ±0.0 > 0.0 ±0.0 - * ±0.0 ±0.0 ±0.0 - * ±0.0 < 0.0 ±π - * ±0.0 -0.0 ±π - * > 0.0 ±0.0 π/2 - * < 0.0 ±0.0 π/2 - * > 0.0 ∞ ±0.0 - * ±∞ anything ±π/2 - * > 0.0 -∞ ±π - * ±∞ ∞ ±π/4 - * ±∞ -∞ ±3π/4 + * $(TR $(TH y) $(TH x) $(TH atan(y, x))) + * $(TR $(TD $(NAN)) $(TD anything) $(TD $(NAN)) ) + * $(TR $(TD anything) $(TD $(NAN)) $(TD $(NAN)) ) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(GT)0.0) $(TD $(PLUSMN)0.0) ) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) ) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(LT)0.0) $(TD $(PLUSMN)$(PI))) + * $(TR $(TD $(PLUSMN)0.0) $(TD -0.0) $(TD $(PLUSMN)$(PI))) + * $(TR $(TD $(GT)0.0) $(TD $(PLUSMN)0.0) $(TD $(PI)/2) ) + * $(TR $(TD $(LT)0.0) $(TD $(PLUSMN)0.0) $(TD $(PI)/2)) + * $(TR $(TD $(GT)0.0) $(TD $(INFIN)) $(TD $(PLUSMN)0.0) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD anything) $(TD $(PLUSMN)$(PI)/2)) + * $(TR $(TD $(GT)0.0) $(TD -$(INFIN)) $(TD $(PLUSMN)$(PI)) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(INFIN)) $(TD $(PLUSMN)$(PI)/4)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD -$(INFIN)) $(TD $(PLUSMN)3$(PI)/4)) * ) */ real atan2(real y, real x) { return std.c.math.atan2l(y,x); } @@ -370,8 +375,8 @@ real atan2(real y, real x) { return std.c.math.atan2l(y,x); } * Calculates the hyperbolic cosine of x. * * $(TABLE_SV - * x cosh(x) invalid? - * ±∞ ±0.0 no + * $(TR $(TH x) $(TH cosh(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)0.0) $(TD no) ) * ) */ real cosh(real x) { return std.c.math.coshl(x); } @@ -380,9 +385,9 @@ real cosh(real x) { return std.c.math.coshl(x); } * Calculates the hyperbolic sine of x. * * $(TABLE_SV - * x sinh(x) invalid? - * ±0.0 ±0.0 no - * ±∞ ±∞ no + * $(TR $(TH x) $(TH sinh(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) $(TD no)) * ) */ real sinh(real x) { return std.c.math.sinhl(x); } @@ -391,9 +396,9 @@ real sinh(real x) { return std.c.math.sinhl(x); } * Calculates the hyperbolic tangent of x. * * $(TABLE_SV - * x tanh(x) invalid? - * ±0.0 ±0.0 no - * ±∞ ±1.0 no + * $(TR $(TH x) $(TH tanh(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)1.0) $(TD no)) * ) */ real tanh(real x) { return std.c.math.tanhl(x); } @@ -408,14 +413,14 @@ real tanh(real x) { return std.c.math.tanhl(x); } * Mathematically, acosh(x) = log(x + sqrt( x*x - 1)) * * $(TABLE_DOMRG - * $(DOMAIN 1..∞) - * $(RANGE 1..log(real.max), ∞) ) + * $(DOMAIN 1..$(INFIN)) + * $(RANGE 1..log(real.max), $(INFIN)) ) * $(TABLE_SV * $(SVH x, acosh(x) ) * $(SV $(NAN), $(NAN) ) * $(SV <1, $(NAN) ) * $(SV 1, 0 ) - * $(SV +∞,+∞) + * $(SV +$(INFIN),+$(INFIN)) * ) */ real acosh(real x) @@ -444,10 +449,10 @@ unittest * ------------- * * $(TABLE_SV - * $(SVH x, asinh(x) ) - * $(SV $(NAN), $(NAN) ) - * $(SV ±0, ±0 ) - * $(SV ±∞,±∞) + * $(SVH x, asinh(x) ) + * $(SV $(NAN), $(NAN) ) + * $(SV $(PLUSMN)0, $(PLUSMN)0 ) + * $(SV $(PLUSMN)$(INFIN),$(PLUSMN)$(INFIN)) * ) */ real asinh(real x) @@ -478,13 +483,13 @@ unittest * * * $(TABLE_DOMRG - * $(DOMAIN -∞..∞) + * $(DOMAIN -$(INFIN)..$(INFIN)) * $(RANGE -1..1) ) * $(TABLE_SV * $(SVH x, acosh(x) ) * $(SV $(NAN), $(NAN) ) - * $(SV ±0, ±0) - * $(SV -∞, -0) + * $(SV $(PLUSMN)0, $(PLUSMN)0) + * $(SV -$(INFIN), -0) * ) */ real atanh(real x) @@ -522,10 +527,10 @@ extern (C) real rndtonl(real x); * Compute square root of x. * * $(TABLE_SV - * x sqrt(x) invalid? - * -0.0 -0.0 no - * <0.0 $(NAN) yes - * +∞ +∞ no + * $(TR $(TH x) $(TH sqrt(x)) $(TH invalid?)) + * $(TR $(TD -0.0) $(TD -0.0) $(TD no)) + * $(TR $(TD $(LT)0.0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no)) * ) */ @@ -577,9 +582,9 @@ creal sqrt(creal z) * Calculates e$(SUP x). * * $(TABLE_SV - * x exp(x) - * +∞ +∞ - * -∞ +0.0 + * $(TR $(TH x) $(TH exp(x))) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) ) + * $(TR $(TD -$(INFIN)) $(TD +0.0) ) * ) */ real exp(real x) { return std.c.math.expl(x); } @@ -588,9 +593,9 @@ real exp(real x) { return std.c.math.expl(x); } * Calculates 2$(SUP x). * * $(TABLE_SV - * x exp2(x) - * +∞ +∞ - * -∞ +0.0 + * $(TR $(TH x) $(TH exp2(x))) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN))) + * $(TR $(TD -$(INFIN)) $(TD +0.0)) * ) */ real exp2(real x) { return std.c.math.exp2l(x); } @@ -603,10 +608,10 @@ real exp2(real x) { return std.c.math.exp2l(x); } * than exp(x)-1. * * $(TABLE_SV - * x e$(SUP x)-1 - * ±0.0 ±0.0 - * +∞ +∞ - * -∞ -1.0 + * $(TR $(TH x) $(TH e$(SUP x)-1)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN))) + * $(TR $(TD -$(INFIN)) $(TD -1.0)) * ) */ @@ -619,15 +624,15 @@ real expm1(real x) { return std.c.math.expm1l(x); } * Returns: * Calculate and return x and exp such that * value =x*2$(SUP exp) and - * .5 <= |x| < 1.0
+ * .5 $(LT)= |x| $(LT) 1.0
* x has same sign as value. * * $(TABLE_SV - * value returns exp - * ±0.0 ±0.0 0 - * +∞ +∞ int.max - * -∞ -∞ int.min - * ±$(NAN) ±$(NAN) int.min + * $(TR $(TH value) $(TH returns) $(TH exp)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD 0)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD int.max)) + * $(TR $(TD -$(INFIN)) $(TD -$(INFIN)) $(TD int.min)) + * $(TR $(TD $(PLUSMN)$(NAN)) $(TD $(PLUSMN)$(NAN)) $(TD int.min)) * ) */ @@ -731,10 +736,10 @@ unittest * cast(int)logb(x). * * $(TABLE_SV - * x ilogb(x) Range error? - * 0 FP_ILOGB0 yes - * ±∞ int.max no - * $(NAN) FP_ILOGBNAN no + * $(TR $(TH x) $(TH ilogb(x)) $(TH Range error?)) + * $(TR $(TD 0) $(TD FP_ILOGB0) $(TD yes)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD int.max) $(TD no)) + * $(TR $(TD $(NAN)) $(TD FP_ILOGBNAN) $(TD no)) * ) */ int ilogb(real x) { return std.c.math.ilogbl(x); } @@ -754,10 +759,10 @@ real ldexp(real n, int exp); /* intrinsic */ * Calculate the natural logarithm of x. * * $(TABLE_SV - * x log(x) divide by 0? invalid? - * ±0.0 -∞ yes no - * < 0.0 $(NAN) no yes - * +∞ +∞ no no + * $(TR $(TH x) $(TH log(x)) $(TH divide by 0?) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD -$(INFIN)) $(TD yes) $(TD no)) + * $(TR $(TD $(LT)0.0) $(TD $(NAN)) $(TD no) $(TD yes)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no)) * ) */ @@ -767,10 +772,10 @@ real log(real x) { return std.c.math.logl(x); } * Calculate the base-10 logarithm of x. * * $(TABLE_SV - * x log10(x) divide by 0? invalid? - * ±0.0 -∞ yes no - * < 0.0 $(NAN) no yes - * +∞ +∞ no no + * $(TR $(TH x) $(TH log10(x)) $(TH divide by 0?) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD -$(INFIN)) $(TD yes) $(TD no)) + * $(TR $(TD $(LT)0.0) $(TD $(NAN)) $(TD no) $(TD yes)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no)) * ) */ @@ -783,11 +788,11 @@ real log10(real x) { return std.c.math.log10l(x); } * log(1 + x). * * $(TABLE_SV - * x log1p(x) divide by 0? invalid? - * ±0.0 ±0.0 no no - * -1.0 -∞ yes no - * <-1.0 $(NAN) no yes - * +∞ -∞ no no + * $(TR $(TH x) $(TH log1p(x)) $(TH divide by 0?) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no) $(TD no)) + * $(TR $(TD -1.0) $(TD -$(INFIN)) $(TD yes) $(TD no)) + * $(TR $(TD $(LT)-1.0) $(TD $(NAN)) $(TD no) $(TD yes)) + * $(TR $(TD +$(INFIN)) $(TD -$(INFIN)) $(TD no) $(TD no)) * ) */ @@ -798,10 +803,10 @@ real log1p(real x) { return std.c.math.log1pl(x); } * log2x * * $(TABLE_SV - * x log2(x) divide by 0? invalid? - * ±0.0 -∞ yes no - * < 0.0 $(NAN) no yes - * +∞ +∞ no no + * $(TR $(TH x) $(TH log2(x)) $(TH divide by 0?) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD -$(INFIN)) $(TD yes) $(TD no) ) + * $(TR $(TD $(LT)0.0) $(TD $(NAN)) $(TD no) $(TD yes) ) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no) ) * ) */ real log2(real x) { return std.c.math.log2l(x); } @@ -817,9 +822,9 @@ real log2(real x) { return std.c.math.log2l(x); } * ----- * * $(TABLE_SV - * x logb(x) Divide by 0? - * ±∞ +∞ no - * ±0.0 -∞ yes + * $(TR $(TH x) $(TH logb(x)) $(TH divide by 0?) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD +$(INFIN)) $(TD no)) + * $(TR $(TD $(PLUSMN)0.0) $(TD -$(INFIN)) $(TD yes) ) * ) */ real logb(real x) { return std.c.math.logbl(x); } @@ -831,11 +836,11 @@ real logb(real x) { return std.c.math.logbl(x); } * be completely subtracted from x. The result has the same sign as x. * * $(TABLE_SV - * x y modf(x, y) invalid? - * ±0.0 not 0.0 ±0.0 no - * ±∞ anything $(NAN) yes - * anything ±0.0 $(NAN) yes - * !=±∞ ±∞ x no + * $(TR $(TH x) $(TH y) $(TH modf(x, y)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD no)t 0.0 $(TD $(PLUSMN)0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD anything) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD anything) $(TD $(PLUSMN)0.0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD !=$(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) $(TD x) $(TD no)) * ) */ real modf(real x, inout real y) { return std.c.math.modfl(x,&y); } @@ -847,9 +852,9 @@ real modf(real x, inout real y) { return std.c.math.modfl(x,&y); } * the same fashion as the basic arithmetic operators. * * $(TABLE_SV - * x scalb(x) - * ±∞ ±∞ - * ±0.0 ±0.0 + * $(TR $(TH x) $(TH scalb(x))) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) ) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) ) * ) */ real scalbn(real x, int n) @@ -864,10 +869,10 @@ real scalbn(real x, int n) * Calculates the cube root x. * * $(TABLE_SV - * x cbrt(x) invalid? - * ±0.0 ±0.0 no - * $(NAN) $(NAN) yes - * ±∞ ±∞ no + * $(TR $(TH $(I x)) $(TH cbrt(x)) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)0.0) $(TD no) ) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) $(TD no) ) * ) */ real cbrt(real x) { return std.c.math.cbrtl(x); } @@ -877,9 +882,9 @@ real cbrt(real x) { return std.c.math.cbrtl(x); } * Returns |x| * * $(TABLE_SV - * x fabs(x) - * ±0.0 +0.0 - * ±∞ +∞ + * $(TR $(TH x) $(TH fabs(x))) + * $(TR $(TD $(PLUSMN)0.0) $(TD +0.0) ) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD +$(INFIN)) ) * ) */ real fabs(real x); /* intrinsic */ @@ -897,10 +902,10 @@ real fabs(real x); /* intrinsic */ * hypot(x, -y) are equivalent. * * $(TABLE_SV - * x y hypot(x, y) invalid? - * x ±0.0 |x| no - * ±∞ y +∞ no - * ±∞ $(NAN) +∞ no + * $(TR $(TH x) $(TH y) $(TH hypot(x, y)) $(TH invalid?)) + * $(TR $(TD x) $(TD $(PLUSMN)0.0) $(TD |x|) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD y) $(TD +$(INFIN)) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD +$(INFIN)) $(TD no)) * ) */ @@ -1028,10 +1033,10 @@ real erfc(real x) { return std.c.math.erfcl(x); } * For reals, lgamma is equivalent to log(fabs(gamma(x))). * * $(TABLE_SV - * x lgamma(x) invalid? - * $(NAN) $(NAN) yes - * integer <= 0 +∞ yes - * ±∞ +∞ no + * $(TR $(TH x) $(TH lgamma(x)) $(TH invalid?)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD integer <= 0) $(TD +$(INFIN)) $(TD yes)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD +$(INFIN)) $(TD no)) * ) */ /* Documentation prepared by Don Clugston */ @@ -1050,16 +1055,16 @@ real lgamma(real x) * Like x!, $(GAMMA)(x+1) = x*$(GAMMA)(x). * * Mathematically, if z.re > 0 then - * $(GAMMA)(z) =$(INTEGRAL)0tz-1e-tdt + * $(GAMMA)(z) =$(INTEGRAL)0$(INFIN)tz-1e-tdt * * $(TABLE_SV - * x $(GAMMA)(x) invalid? - * $(NAN) $(NAN) yes - * ±0.0 ±∞ yes - * integer > 0 (x-1)! no - * integer < 0 $(NAN) yes - * +∞ +∞ no - * -∞ $(NAN) yes + * $(TR $(TH x) $(TH $(GAMMA)(x)) $(TH invalid?)) + * $(TR $(TD $(NAN)) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD $(PLUSMN)0.0) $(TD $(PLUSMN)$(INFIN)) $(TD yes)) + * $(TR $(TD integer $(GT)0) $(TD (x-1)!) $(TD no)) + * $(TR $(TD integer $(LT)0) $(TD $(NAN)) $(TD yes)) + * $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no)) + * $(TR $(TD -$(INFIN)) $(TD $(NAN)) $(TD yes)) * ) * * References: @@ -1153,16 +1158,16 @@ real trunc(real x) { return std.c.math.truncl(x); } * If |n - x / y| == 0.5, n is even. * If the result is zero, it has the same sign as x. * Otherwise, the sign of the result is the sign of x / y. - * Precision mode has no affect on the remainder functions. + * Precision mode has no effect on the remainder functions. * * remquo returns n in the parameter n. * * $(TABLE_SV - * x y remainder(x, y) n invalid? - * ±0.0 not 0.0 ±0.0 0.0 no - * ±∞ anything $(NAN) ? yes - * anything ±0.0 $(NAN) ? yes - * != ±∞ ±∞ x ? no + * $(TR $(TH x) $(TH y) $(TH remainder(x, y)) $(TH n) $(TH invalid?)) + * $(TR $(TD $(PLUSMN)0.0) $(TD no)t 0.0 $(TD $(PLUSMN)0.0) $(TD 0.0) $(TD no)) + * $(TR $(TD $(PLUSMN)$(INFIN)) $(TD anything) $(TD $(NAN)) $(TD ?) $(TD yes)) + * $(TR $(TD anything) $(TD $(PLUSMN)0.0) $(TD $(NAN)) $(TD ?) $(TD yes)) + * $(TR $(TD != $(PLUSMN)$(INFIN)) $(TD $(PLUSMN)$(INFIN)) $(TD x) $(TD ?) $(TD no)) * ) */ real remainder(real x, real y) { return std.c.math.remainderl(x, y); } @@ -1328,7 +1333,7 @@ unittest } /********************************* - * Return !=0 if e is ±∞. + * Return !=0 if e is $(PLUSMN)$(INFIN). */ int isinf(real e) @@ -1416,8 +1421,8 @@ real nan(char[] tagp) { return std.c.math.nanl(toStringz(tagp)); } /****************************************** * Calculates the next representable value after x in the direction of y. * - * If y > x, the result will be the next largest floating-point value; - * if y < x, the result will be the next smallest value. + * If y $(GT) x, the result will be the next largest floating-point value; + * if y $(LT) x, the result will be the next smallest value. * If x == y, the result is y. * The FE_INEXACT and FE_OVERFLOW exceptions will be raised if x is finite and * the function result is infinite. The FE_INEXACT and FE_UNDERFLOW @@ -1437,11 +1442,11 @@ real nextafter(real x, real y) /******************************************* * Returns the positive difference between x and y. * Returns: - * - *
x, y fdim(x, y) - *
x > y x - y - *
x <= y +0.0 - *
+ * $(TABLE_SV + * $(TR $(TH x, y) $(TH fdim(x, y))) + * $(TR $(TD x $(GT) y) $(TD x - y)) + * $(TR $(TD x $(LT)= y) $(TD +0.0)) + * ) */ real fdim(real x, real y) { return (x > y) ? x - y : +0.0; } @@ -1513,42 +1518,42 @@ real pow(real x, int n) * Calculates x$(SUP y). * * $(TABLE_SV - * - * x y pow(x, y) div 0 invalid? - * - * anything ±0.0 1.0 no no - * - * |x| > 1 +∞ +∞ no no - * - * |x| < 1 +∞ +0.0 no no - * - * |x| > 1 -∞ +0.0 no no - * - * |x| < 1 -∞ +∞ no no - * - * +∞ > 0.0 +∞ no no - * - * +∞ < 0.0 +0.0 no no - * - * -∞ odd integer > 0.0 -∞ no no - * - * -∞ > 0.0, not odd integer +∞ no no - * - * -∞ odd integer < 0.0 -0.0 no no - * - * -∞ < 0.0, not odd integer +0.0 no no - * - * ±1.0 ±∞ $(NAN) no yes - * - * < 0.0 finite, nonintegral $(NAN) no yes - * - * ±0.0 odd integer < 0.0 ±∞ yes no - * - * ±0.0 < 0.0, not odd integer +∞ yes no - * - * ±0.0 odd integer > 0.0 ±0.0 no no - * - * ±0.0 > 0.0, not odd integer +0.0 no no + * $(TR + * $(TH x) $(TH y) $(TH pow(x, y)) $(TH div 0) $(TH invalid?)) + * $(TR + * $(TD anything) $(TD $(PLUSMN)0.0) $(TD 1.0) $(TD no) $(TD no) ) + * $(TR + * $(TD |x| $(GT) 1) $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no) ) + * $(TR + * $(TD |x| $(LT) 1) $(TD +$(INFIN)) $(TD +0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD |x| $(GT) 1) $(TD -$(INFIN)) $(TD +0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD |x| $(LT) 1) $(TD -$(INFIN)) $(TD +$(INFIN)) $(TD no) $(TD no) ) + * $(TR + * $(TD +$(INFIN)) $(TD $(GT) 0.0) $(TD +$(INFIN)) $(TD no) $(TD no) ) + * $(TR + * $(TD +$(INFIN)) $(TD $(LT) 0.0) $(TD +0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD -$(INFIN)) $(TD odd integer $(GT) 0.0) $(TD -$(INFIN)) $(TD no) $(TD no) ) + * $(TR + * $(TD -$(INFIN)) $(TD $(GT) 0.0, not odd integer) $(TD +$(INFIN)) $(TD no) $(TD no)) + * $(TR + * $(TD -$(INFIN)) $(TD odd integer $(LT) 0.0) $(TD -0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD -$(INFIN)) $(TD $(LT) 0.0, not odd integer) $(TD +0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD $(PLUSMN)1.0) $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD no) $(TD yes) ) + * $(TR + * $(TD $(LT) 0.0) $(TD finite, nonintegral) $(TD $(NAN)) $(TD no) $(TD yes)) + * $(TR + * $(TD $(PLUSMN)0.0) $(TD odd integer $(LT) 0.0) $(TD $(PLUSMN)$(INFIN)) $(TD yes) $(TD no) ) + * $(TR + * $(TD $(PLUSMN)0.0) $(TD $(LT) 0.0, not odd integer) $(TD +$(INFIN)) $(TD yes) $(TD no)) + * $(TR + * $(TD $(PLUSMN)0.0) $(TD odd integer $(GT) 0.0) $(TD $(PLUSMN)0.0) $(TD no) $(TD no) ) + * $(TR + * $(TD $(PLUSMN)0.0) $(TD $(GT) 0.0, not odd integer) $(TD +0.0) $(TD no) $(TD no) ) * ) */ @@ -1696,12 +1701,12 @@ bool isNegZero(real x) * eg, 0x1.F8p+60 and 0x1.F1p+60 are equal to 5 bits of precision. * * $(TABLE_SV - * x y feqrel(x, y) - * x x real.mant_dig - * x >= 2*x 0 - * x <= x/2 0 - * $(NAN) any 0 - * any $(NAN) 0 + * $(TR $(TH x) $(TH y) $(TH feqrel(x, y))) + * $(TR $(TD x) $(TD x) $(TD real.mant_dig)) + * $(TR $(TD x) $(TD $(GT)= 2*x) $(TD 0)) + * $(TR $(TD x) $(TD $(LT)= x/2) $(TD 0)) + * $(TR $(TD $(NAN)) $(TD any) $(TD 0)) + * $(TR $(TD any) $(TD $(NAN)) $(TD 0)) * ) */