Chapter Contents |
Previous |
Next |
modf |
Portability: | ISO/ANSI C conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <math.h> double modf(double y, double *p);
DESCRIPTION |
modf
separates an argument of type
double
into
fractional and integer parts.
RETURN VALUE |
modf
returns the fractional part of the argument
y
with the same sign as
y
. The integer
part of
y
, expressed as a floating-point
number, is stored in the location referenced by the pointer
p
.
IMPLEMENTATION |
modf
is implemented as a built-in function unless it is undefined by an
#undef
statement.
EXAMPLE |
#include <math.h> #include <stdio.h> main() { double weight; double intweight; float limit = 0.5; puts("Enter a weight"); scanf("%lf",&weight); /* Check to see if weight is negative. */ if (weight < 0) { puts("Weight can not be a negative number"); exit(1); } /* Test whether fractional part equals or exceeds limit. */ if (modf(weight, &intweight) >= limit) weight = intweight + 1; /* If yes, add 1 to weight. */ else weight = intweight; /* Otherwise, round down weight. */ printf("Your weight rounded off to the nearest pound is %f\n", weight); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.