www.delorie.com/gnu/docs/glibc/libc_415.html | search |
Buy the book! | |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The functions listed here perform operations such as rounding and truncation of floating-point values. Some of these functions convert floating point numbers to integer values. They are all declared in `math.h'.
You can also convert floating-point numbers to integers simply by
casting them to int
. This discards the fractional part,
effectively rounding towards zero. However, this only works if the
result can actually be represented as an int
---for very large
numbers, this is impossible. The functions listed here return the
result as a double
instead to get around this problem.
double
. Thus, ceil (1.5)
is 2.0
.
double
. Thus, floor
(1.5)
is 1.0
and floor (-1.5)
is -2.0
.
trunc
functions round x towards zero to the nearest
integer (returned in floating-point format). Thus, trunc (1.5)
is 1.0
and trunc (-1.5)
is -1.0
.
If x was not initially an integer, these functions raise the inexact exception.
rint
functions, but
do not raise the inexact exception if x is not an integer.
rint
, but they round halfway
cases away from zero instead of to the nearest even integer.
rint
, but they return a
long int
instead of a floating-point number.
rint
, but they return a
long long int
instead of a floating-point number.
round
, but they return a
long int
instead of a floating-point number.
round
, but they return a
long long int
instead of a floating-point number.
-1
and 1
, exclusive). Their sum
equals value. Each of the parts has the same sign as value,
and the integer part is always rounded toward zero.
modf
stores the integer part in *integer-part
, and
returns the fractional part. For example, modf (2.5, &intpart)
returns 0.5
and stores 2.0
into intpart
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
webmaster | delorie software privacy |
Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |