|
Low-level Mathematical Functions which take advantage of the IEEE754 ABI.
License: BSD style: see license.txt, Digital Mars. Authors: Don Clugston, Walter Bright, Sean Kelly $(DDOC_MODULE_MEMBERS These flags indicate that an exceptional floating-point condition has occured. They indicate that a NaN or an infinity has been generated, that a result is inexact, or that a signalling NaN has been encountered. The return values of the properties should be treated as booleans, although each is returned as an int, for speed. Example: real a=3.5;
// Set all the flags to zero
resetIeeeFlags();
assert(!ieeeFlags.divByZero);
// Perform a division by zero.
a/=0.0L;
assert(a==real.infinity);
assert(ieeeFlags.divByZero);
// Create a NaN
a*=0.0L;
assert(ieeeFlags.invalid);
assert(isNaN(a));
// Check that calling func() has no effect on the
// status flags.
IeeeFlags f = ieeeFlags;
func();
assert(ieeeFlags == f);
Returns the old rounding mode. When changing the rounding mode, it is almost always necessary to restore it at the end of the function. Typical usage: auto oldrounding = setIeeeRounding(RoundingMode.ROUNDDOWN);
scope (exit) setIeeeRounding(oldrounding);
Returns: the old precision. This is not supported on all platforms. Returns: Calculate and return x and exp such that value =x*2 and .5 <= |x| < 1.0 x has same sign as value.
References: frexp If x is not a special value, the result is the same as cast(int)logb(x). Remarks: This function is consistent with IEEE754R, but it differs from the C function of the same name in the return value of infinity. (in C, ilogb (real.infinity)== int.max). Note that the special return values may all be equal.
If x is subnormal, it is treated as if it were normalized. For a positive, finite x: 1 <= x * FLT_RADIX < FLT_RADIX
scalbn handles underflow and overflow in the same fashion as the basic arithmetic operators.
If either of x or y is NAN, it will be returned. Returns:
BUGS: Not currently implemented - rounds twice. On x86 CPUs, this is a very efficient operation; almost twice as fast as calculating sin(y) and cos(y) seperately, and is the preferred method when both are required. (Need one for each format because subnormal floats might be converted to normal reals) bool isIdentical (ireal x, ireal y); bool isIdentical (creal x, creal y); Same as ==, except that positive and negative zero are not identical, and two NANs are identical if they have the same 'payload'. int isSubnormal (double d); int isSubnormal (real x); Does not affect any floating-point flags double nextDoubleUp (double x); float nextFloatUp (float x); Return the least number greater than x that is representable as a real; thus, it gives the next point on the IEEE number line. This function is included in the forthcoming IEEE 754R standard.
nextDoubleUp and nextFloatUp are the corresponding functions for the IEEE double and IEEE float number lines. double nextDoubleDown (double x); float nextFloatDown (float x); Return the greatest number less than x that is representable as a real; thus, it gives the previous point on the IEEE number line. Note: This function is included in the forthcoming IEEE 754R standard. Special values: real.infinity real.max real.min*real.epsilon 0.0 0.0 -real.min*real.epsilon -0.0 -real.min*real.epsilon -real.max -real.infinity -real.infinity -real.infinity NAN NAN nextDoubleDown and nextFloatDown are the corresponding functions for the IEEE double and IEEE float number lines. 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 x == y, the result is y. Remarks: This function is not generally very useful; it's almost always better to use the faster functions nextUp() or nextDown() instead. IEEE 754 requirements not implemented: 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 exceptions will be raised if the function value is subnormal, and x is not equal to y. Returns: the number of significand bits which are equal in x and y. eg, 0x1.F8p+60 and 0x1.F1p+60 are equal to 5 bits of precision.
Remarks: This is a very fast operation, suitable for use in speed-critical code. Formally, the result is the arithmetic mean of the binary significands of x and y, multiplied by the geometric mean of the binary exponents of x and y. x and y must have the same sign, and must not be NaN. Note: this function is useful for ensuring O(log n) behaviour in algorithms involving a 'binary chop'. Special cases: If x and y are within a factor of 2, (ie, feqrel(x, y) > 0), the return value is the arithmetic mean (x + y) / 2. If x and y are even powers of 2, the return value is the geometric mean, ieeeMean (x, y) = sqrt(x * y). For 80-bit or 128-bit reals, the largest possible payload is 0x3FFF_FFFF_FFFF_FFFF. For doubles, it is 0x3_FFFF_FFFF_FFFF. For floats, it is 0x3F_FFFF. Returns: the integer payload as a ulong. For 80-bit or 128-bit reals, the largest possible payload is 0x3FFF_FFFF_FFFF_FFFF. For doubles, it is 0x3_FFFF_FFFF_FFFF. For floats, it is 0x3F_FFFF. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Portions Copyright (C) 2001-2005 Digital Mars. :: page rendered by CandyDoc |