digitalmars.com                      
Last update Sun Mar 8 11:28:39 2009
Runtime Library
Reference


· Constants
· Data types

Standard C
· assert.h
· complex.h
· ctype.h
· fenv.h
· float.h
· locale.h
· math.h
· setjmp.h
· signal.h
· stdarg.h
· stddef.h
· stdio.h
· stdlib.h
· string.h
· time.h


Standard C++
· IOstream
· new


Win32
· gc.h


DOS, DOS32, Win16
· bios.h
· cerror.h
· disp.h
· dos.h
· dos.h part 2
· emm.h
· handle.h
· int.h
· msmouse.h
· sound.h
· swap.h
· tsr.h
· winio.h


Other C
· bitops.h
· conio.h
· controlc.h
· direct.h
· fltpnt.h
· io.h
· page.h
· process.h
· search.h
· sys\stat.h
· tabsize.h
· trace.h
· utime.h
· unmangle.h
· util.h


Other C++
· regexp.h
· class complex


fltpnt.h


copysign

Header
fltpnt.h
Prototype
double copysign(double x, double y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
Description
These functions copy the sign bit of y into x, but do not trigger a signalling NaN.
Return Value
Returns x with the same sign as y.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* 	Example for copysign 	*/

#include <stdio.h> 
#include <fltpnt.h> 

void main () 
{
   double result, x, y; 

   x = 0.34; 
   y = -1.9; 
   result = copysign (x, y); 
   printf ("The result is %g\n", result); 
}
Output
The result is -0.34

nearbyint

Header
fltpnt.h
Prototype
double nearbyint(double x);
float nearbyintf(float x);
long double nearbyintl(long double x);
Description
Rounds x to the nearest integer value, using the current rounding mode. Unlike the rint functions, nearbyint does not raise the FE_INEXACT exception.
Return Value
x rounded to an integer value.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
ceil Functions
floor Functions
rint
rndtol
rndtonl
round Functions
trunc Functions
Example
/* 	Example of nearbyint
	Also demonstrates nearbyintf 
*/ 

#include <stdlib.h>
#include <stdio.h>
#include <fltpnt.h>

void main ()
{   
   double d; 
   printf (" Enter a double: ");
   scanf ("%lg", &d); 
   printf ("\nnearbyint(%g)=%g\n", d,
	      nearbyint (d)); 
} 
Output
Enter a double: 3.14
nearbyint(3.14)= 3

nextafter

Header
fltpnt.h
Prototype
double nextafter(double x, double y);
float nextafterf(float x, float y)
long double nextafterl(long double x, long double y);
Description
Calculates the next representable value after x in the direction of y.
Return Value
If y is greater than x, the result will be the next largest floating-point value; if y is less than x, the result will be the next smallest value. If x and y are equal, the result is x. 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.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* 	Example for nextafter
	Also demonstrates nextafterf 
*/ 

#include <stdio.h>
#include <stdlib.h> 
#include <math.h>
#include <fltpnt.h>

void main ()
{   
   double d1, d2, r; 
   printf (" Enter two doubles: ");
   scanf ("%lg %lg", &d1, &d2); 

   r = nextafter(d1, d2);
   printf (" nextafter(%g, %g)=%. 16f\n", d1, 
   d2, r);
} 
Output
Enter two doubles: 1 2
nextafter(1, 2)= 1.0000000000000002

remainder

Header
fltpnt.h
fltenv.h (required for exception values)
Prototype
double remainder(double x, double y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
Description
Computes the remainder of x / y, following the IEEE standard.
Return Value
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.

Special Results

value of x 		value of y 	return value 	invalid?
+-0.0 			not 0.0 	+-0.0 		no 
+-INFINITY 		anything 	NAN 		yes 
anything 		+-0.0 		NAN 		yes 
!= +-INFINITY 		+-INFINITY 	x 		no 
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
div
ldiv
fmod Functions
remquo Functions
Example
/* 	Example for remainer
	Also demonstrates remainderf 
*/ 

#include <stdio.h>
#include <stdlib.h> 
#include <fltpnt.h>

void main ()
{   
   double d1, d2, r; 
   printf (" Enter two doubles: ");
   scanf ("%lg %lg", &d1, &d2); 

   r = remainder(d1, d2);
   printf (" remainder(%g, %g)=%g\n", d1, d2, r); 
} 
Output
Enter two doubles: 16 9
remainder(16, 9)= 7

remquo

Header
fltpnt.h
fltenv.h (required for exception values)
Prototype
double remquo(double x, double y, int * quo);
float remquof(float x, float y, int * quo);
long double remquol(long double x, long double y, int * quo);
Description
Calculates the same value as the remainder functions, and places the integral quotient of x / y into the int pointed to by quo. For an x value much larger than y, this function may be unable to return an exact value for the quotient.
Return Value
The same value as remainder(x, y).

Special Results

value of x 	value of y 	returns 	quo 	invalid?
±0.0 		not 0.0 	±0.0 		0.0 	no 
±INFINITY 	anything 	NAN 		? 	yes 
anything 	±0.0 		NAN 		? 	yes 
!= ±INFINITY 	±INFINITY 	x 		?	no 
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
remainder Functions
Example
/* 	Example for remquo
	Also demonstrates remquof 
*/ 

#include <stdio.h>
#include <stdlib.h>
#include <fltpnt.h>

void main ()
{   
   double d1, d2, r;
   int q; 

   printf (" Enter two doubles: ");
   scanf ("%lg %lg", &d1, &d2); 

   r = remquo(d1, d2, &q);
   printf (" remquo(%g, %g, &q)=%g\nq = %d", d1, 
	     d2, r, q);
} 
Output
Enter two doubles: 16 9
remquo(16, 9, &q)= 7
q = 1

rint

Header
math.h
Prototype
double rint(double x);
float rintf(float x);
long double rintl(long double x);
Description
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. The nearbyint functions perform the same operation, but do not set the FE_INEXACT exception.
Return Value
x rounded to an integer value.
Compatibility
ANSI C99 7.12.9.4, DOS, Windows 3.x, Phar Lap, DOSX, Win32
See Also
rndtol
rndtonl
round Functions
Example
/* 	Example of rint
	Also demonstrates rintf 
*/ 

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

void main ()
{   
   double d; 

   printf (" Enter a double: ");
   scanf ("%lg", &d); 
   printf ("\nrint(%g) = %g\n", d, rint(d));
} 
Output
Enter a double: 3.14

rint(3.14) = 3

rndtol

Header
fltpnt.h
Prototype
long rndtol(double x);
long rndtonl(double x);
Description
Returns x rounded to a long value. If the integer value of x is greater than the maximum value of a long, the result is indeterminate.

The rndtol function uses the current rounding mode. The rndtonl function uses the FE_TONEAREST rounding mode.

Return Value
x rounded to a long.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
rint
round Functions
trunc Functions
Example
/* 	Example of rndtol */ 

#include <stdlib.h>
#include <stdio.h>
#include <fltpnt.h>

void main ()
{   
   double d; 

   printf (" Enter a double: ");
   scanf ("%lg", &d); 
   printf ("\nrndtol(%g)=%ld\n", d, rndtol (d)); } 



/* 	Example of rndtonl */ 

#include <stdlib.h>
#include <stdio.h> 
#include <fltpnt.h>

void main ()
{   
   double d; 
   printf (" Enter a double: ");
   scanf ("%lg", &d); 
   printf ("\nrndtonl(%g)=%ld\n", d,
	   rndtonl (d)); 
} 
Output
Enter a double: 3.14

rndtol(3.14)= 3

Enter a double: 3.14

rndtonl(3.14)= 3

round

Header
fltpnt.h
Prototype
double round(double x);
float roundf(float x);
long double roundl(long double x);
Description
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.
Return Value
x rounded to the nearest integer value.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
rint
rndtol
rndtonl
Example
/* 	Example of round
	Also demonstrates roundf 
*/ 

#include <stdlib.h>
#include <stdio.h>
#include <fltpnt.h>

void main ()
{   
   double d; 
   printf (" Enter a double: ");
   scanf ("%lg", &d); 
   printf ("\nround(%g)=%g\n", d, round (d));
} 
Output
Enter a double: 3.14

round(3.14)= 3

scalb

Header
fltpnt.h
Prototype
double scalb(double x, long n);
float scalbf(float x, long n);
long double scalbl(long double x, long n);
Description
Calculates x * FLT_RADIXn efficiently, without calculating FLT_RADIX n explicitly. scalb handles underflow and overflow in the same fashion as the basic arithmetic operators.
Return Value
The value of x * FLT_RADIXn .

Special Results

value of x/return value
+-INFINITY
+-INFINITY
+-0.0
+-0.0
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
Example
/* 	Example of scalb
	Also demonstrates scalbf 
*/ 

#include <stdlib.h>
#include <stdio.h> 
#include <fltpnt.h>
#include <float.h> 

void main ()
{   
   double d;
   long l; 

   printf (" Enter a double and an int: ");
   scanf ("%lg %ld", &d, &l); 
   printf ("\n%g * %d^%ld=%g\n", d, FLT_RADIX,
	    l, scalb (d, l)); 
} 
Output
Enter a double and an int: 10 6

10 * 2^6= 640

trunc

Header
fltpnt.h
Prototype
double trunc(double x);
float truncf(float x);
long double truncl(long double x);
Description
Returns the integer portion of x, dropping the fractional portion. This is also know as "chop" rounding.
Return Value
x without its fractional part.
Compatibility
DOS Windows 3.x Phar Lap DOSX Win32
See Also
ceil Functions
floor Functions
rint
rndtol
rndtonl
round Functions
Example
/* 	Example of trunc 
	Also demonstrates truncl, truncf 
*/ 

#include <stdlib.h>
#include <stdio.h>
#include <fltpnt.h>

void main () 
{   
   double d; 

   printf (" Enter a double: "); 
   scanf ("%lg", &d); 
   printf ("\ntrunc(%g)=%g\n", d, trunc (d)); 
} 
Output
Enter a double: 3.14

trunc(3.14)= 3