www.digitalmars.com Home | Search | D | Comments
Last update Sat Sep 24 15:33:41 2005
D
Language
Phobos
Comparisons


object

std
 std.base64
 std.boxer
 std.compiler
 std.conv
 std.ctype
 std.date
 std.file
 std.format
 std.gc
 std.intrinsic
 std.math
 std.md5
 std.mmfile
 std.openrj
 std.outbuffer
 std.path
 std.process
 std.random
 std.recls
 std.regexp
 std.socket
 std.socketstream
 std.stdint
 std.stdio
 std.cstream
 std.stream
 std.string
 std.system
 std.thread
 std.uri
 std.utf
 std.zip
 std.zlib

std.windows

std.linux

std.c
 std.c.stdio

std.c.windows

std.c.linux

std.math

const real E;

e

const real LOG2T;

log210

const real LOG2E;

log2e

const real LOG2;

log102

const real LOG10E;

log10e

const real LN2;

ln 2

const real LN10;

ln 10

const real PI;

π

const real PI_2;

π / 2

const real PI_4;

π / 4

const real M_1_PI;

1 / π

const real M_2_PI;

2 / π

const real M_2_SQRTPI;

2 / √π

const real SQRT2;

√2

const real SQRT1_2;

√½

real cos(real x);

Returns cosine of x. x is in radians.

Special Values
x cos( x) invalid?
NAN NAN yes
±∞ NAN yes

real sin(real x);

Returns sine of x. x is in radians.

Special Values
x sin( x) invalid?
NAN NAN yes
±0.0 ±0.0 no
±∞ NAN yes

real tan(real x);

Returns tangent of x. x is in radians.

Special Values
x tan( x) invalid?
NAN NAN yes
±0.0 ±0.0 no
±∞ NAN yes

real acos(real x);

Calculates the arc cosine of x, returning a value ranging from -π/2 to π/2.

Special Values
x acos( x) invalid?
>1.0 NAN yes
<-1.0 NAN yes
NAN NAN yes

real asin(real x);

Calculates the arc sine of x, returning a value ranging from -π/2 to π/2.

Special Values
x asin( x) invalid?
±0.0 ±0.0 no
>1.0 NAN yes
<-1.0 NAN yes

real atan(real x);

Calculates the arc tangent of x, returning a value ranging from -π/2 to π/2.

Special Values
x atan( x) invalid?
±0.0 ±0.0 no
±∞ NAN yes

real atan2(real x,real y);

Calculates the arc tangent of y / x, returning a value ranging from -π/2 to π/2.

Special Values
x y atan( x, y)
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

real cosh(real x);

Calculates the hyperbolic cosine of x.

Special Values
x cosh( x) invalid?
±∞ ±0.0 no

real sinh(real x);

Calculates the hyperbolic sine of x.

Special Values
x sinh( x) invalid?
±0.0 ±0.0 no
±∞ ±∞ no

real tanh(real x);

Calculates the hyperbolic tangent of x.

Special Values
x tanh( x) invalid?
±0.0 ±0.0 no
±∞ ±1.0 no

long rndtol(real x);

Returns x rounded to a long value using the current rounding mode. If the integer value of x is greater than long.max, the result is indeterminate.

realC rndtonl(real x);

Returns x rounded to a long value using the FE_TONEAREST rounding mode. If the integer value of x is greater than long.max, the result is indeterminate.

float sqrt(float x);
double sqrt(double x);
real sqrt(real x);

Compute square root of x.

Special Values
x sqrt( x) invalid?
-0.0 -0.0 no
<0.0 NAN yes
+∞ +∞ no

real exp(real x);

Calculates e x.

Special Values
x exp( x)
+∞ +∞
-∞ +0.0

real exp2(real x);

Calculates 2 x.

Special Values
x exp2( x)
+∞ +∞
-∞ +0.0

real expm1(real x);

Calculates the value of the natural logarithm base (e) raised to the power of x, minus 1.

For very small x, expm1( x) is more accurate than exp( x)-1.

Special Values
x e x-1
±0.0 ±0.0
+∞ +∞
-∞ -1.0

real frexp(real value,out int exp);

Separate floating point value into significand and exponent.

Returns:

Calculate and return x and exp such that value =x*2 exp and .5 <= |x| < 1.0
x has same sign as value.

Special Values
value returns exp
±0.0 ±0.0 0
+∞ +∞ int.max
-∞ -∞ int.min
±NAN ±NAN int.min

int ilogb(real x);

Extracts the exponent of x as a signed integral value.

If x is not a special value, the result is the same as cast(int)logb( x).

Special Values
x ilogb( x) Range error?
0 FP_ILOGB0 yes
±∞ +∞ no
NAN FP_ILOGBNAN no

real ldexp(real n,int exp);

Compute n * 2 exp

References:

frexp

real log(real x);

Calculate the natural logarithm of x.

Special Values
x log( x) divide by 0? invalid?
±0.0 -∞ yes no
< 0.0 NAN no yes
+∞ +∞ no no

real log10(real x);

Calculate the base-10 logarithm of x.

Special Values
x log10( x) divide by 0? invalid?
±0.0 -∞ yes no
< 0.0 NAN no yes
+∞ +∞ no no

real log1p(real x);

Calculates the natural logarithm of 1 + x.

For very small x, log1p( x) will be more accurate than log(1 + x).

Special Values
x log1p( x) divide by 0? invalid?
±0.0 ±0.0 no no
-1.0 -∞ yes no
<-1.0 NAN no yes
+∞ -∞ no no

real log2(real x);

Calculates the base-2 logarithm of x: log2 x

Special Values
x log2( x) divide by 0? invalid?
±0.0 -∞ yes no
< 0.0 NAN no yes
+∞ +∞ no no

real logb(real x);

Extracts the exponent of x as a signed integral value.

If x is subnormal, it is treated as if it were normalized. For a positive, finite x:

	1 <=   x * FLT_RADIX-  logb(  x) < FLT_RADIX
	
Special Values
x logb( x) Divide by 0?
±∞ +∞ no
±0.0 -∞ yes

real modf(real x,inout real y);

Calculates the remainder from the calculation x/ y.

Returns:

The value of x - i * y, where i is the number of times that y can be completely subtracted from x. The result has the same sign as x.

Special Values
x y modf( x, y) invalid?
±0.0 not 0.0 ±0.0 no
±∞ anything NAN yes
anything ±0.0 NAN yes
!=±∞ ±∞ x no

real scalbn(real x,int n);

Efficiently calculates x * 2 n.

scalbn handles underflow and overflow in the same fashion as the basic arithmetic operators.

Special Values
x scalb( x)
±∞ ±∞
±0.0 ±0.0

real cbrt(real x);

Calculates the cube root x.

Special Values
x cbrt( x) invalid?
±0.0 ±0.0 no
NAN NAN yes
±∞ ±∞ no

real fabs(real x);

Returns | x|

Special Values
x fabs( x)
±0.0 +0.0
±∞ +∞

real hypot(real x,real y);

Calculates the length of the hypotenuse of a right-angled triangle with sides of length x and y. The hypotenuse is the value of the square root of the sums of the squares of x and y:

sqrt( x² + y²)

Note that hypot( x, y), hypot( y, x) and hypot( x, - y) are equivalent.

Special Values
x y hypot( x, y) invalid?
x ±0.0 | x| no
±∞ y +∞ no
±∞ NAN +∞ no

real erf(real x);

Returns the error function of x.

error function

real erfc(real x);

Returns the complementary error function of x, which is 1 - erf( x).

complementary error function

real lgamma(real x);

Calculates ln |Γ( x)|

real tgamma(real x);

Calculates the gamma function Γ( x)

real ceil(real x);

Returns the value of x rounded upward to the next integer (toward positive infinity).

real floor(real x);

Returns the value of x rounded downward to the next integer (toward negative infinity).

real nearbyint(real x);

Rounds x to the nearest integer value, using the current rounding mode.

Unlike the rint functions, nearbyint does not raise the FE_INEXACT exception.

real rint(real x);

Rounds x to the nearest integer value, using the current rounding mode. If the return value is not equal to x, the FE_INEXACT exception is raised. nearbyint performs the same operation, but does not set the FE_INEXACT exception.

long lrint(real x);

Rounds x to the nearest integer value, using the current rounding mode.

real round(real x);

Return the value of x rounded to the nearest integer. If the fractional part of x is exactly 0.5, the return value is rounded to the even integer.

long lround(real x);

Return the value of x rounded to the nearest integer.

If the fractional part of x is exactly 0.5, the return value is rounded away from zero.

real trunc(real x);

Returns the integer portion of x, dropping the fractional portion.

This is also know as "chop" rounding.

real remainder(real x,real y);
real remquo(real x,real y,out int n);

Calculate the remainder x REM y, following IEC 60559.

REM is the value of x - y * n, where n is the integer nearest the exact value of x / y. 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.

remquo returns n in the parameter n.

Special Values
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

int isnan(real e);

Returns !=0 if e is a NaN.

int isfinite(real e);

Returns !=0 if e is finite.

int isnormal(float x);
int isnormal(double d);
int isnormal(real e);

Returns !=0 if x is normalized.

int issubnormal(float f);
int issubnormal(double d);
int issubnormal(real e);

Is number subnormal? (Also called "denormal".) Subnormals have a 0 exponent and a 0 most significant mantissa bit.

int isinf(real e);

Return !=0 if e is ±∞.

int signbit(real e);

Return 1 if sign bit of e is set, 0 if not.

real copysign(real to,real from);

Return a value composed of to with from's sign bit.

real nan(char[] tagp);

Creates a quiet NAN with the information from tagp[] embedded in it.

real nextafter(real x,real y);

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 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 exceptions will be raised if the function value is subnormal, and x is not equal to y.

real fdim(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

real fmax(real x,real y);

Returns the larger of x and y.

real fmin(real x,real y);

Returns the smaller of x and y.

real fma(real x,real y,real z);

Returns ( x * y) + z, rounding only once according to the current rounding mode.

real pow(real x,uint n);
real pow(real x,int n);

Fast integral powers.

real pow(real x,real y);

Calculates x y.

Special Values
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

int feqrel(real x,real y);

To what precision is x equal to y?

Returns:

the number of mantissa bits which are equal in x and y. eg, 0x1.F8p+60 and 0x1.F1p+60 are equal to 5 bits of precision.

Special Values
x y feqrel( x, y)
x x real.mant_dig
x >= 2* x 0
x <= x/2 0
NAN any 0
any NAN 0

Feedback and Comments

Add feedback and comments regarding this page.
Copyright © 1999-2005 by Digital Mars, All Rights Reserved


Valid HTML 4.01 Transitional