.TH modf() "" "" "General Function (libc)"
.PC "Separate integral part and fraction"
.B "#include <math.h>"
\fBdouble modf(\fIreal\^\fB, \fIip\^\fB)\fR
\fBdouble \fIreal, *ip\^\fB;\fR
.PP
.B modf()
is the floating-point modulus function.
It returns the fractional part of its argument
.IR real ,
and stores the integral part in the
location to which
.I ip
points.
These numbers satisfy the equation \fIreal\fR = \fIf\fR + \fI*ip\fR.
.SH Example
This example prompts for a number from the keyboard, then uses
.B modf()
to calculate the number's fractional portion.
.DM
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
.DE
.DM
main()
{
	double real, fp, ip;
	char string[64];
.DE
.DM
	for (;;) {
		printf("Enter number: ");
		if (gets(string) == 0)
			break;
.DE
.DM
		real = atof(string);
		fp = modf(real, &ip);
		printf("%lf is the integral part of %lf\en",
			ip, real);
		printf("%lf is the fractional part of %lf\en",
			fp, real);
	}
}
.DE
.SH "See Also"
.Xr "atof()," atof
.Xr "ceil()," ceil
.Xr "fabs()," fabs
.Xr "floor()," floor
.Xr "frexp()," frexp
.Xr "ldexp()," ldexp
.Xr "libc" libc
.br
\*(AS, \(sc7.5.4.6
.br
\*(PX Standard, \(sc8.1
.SH Notes
In releases prior to version 4.0, the \*(CO implementation of
.B modf()
handled negative numbers by returning a integral part less than
.IR real ,
and a positive fraction.
Now, it returns an integral part greater than
.IR real ,
and a negative fraction.
For example, the old version of \fBmodf()\fR would transform \-1.9 into
an integer of \-2.0 and a fraction of 0.1; whereas the current version
transforms \-1.9 into an integer of \-1.0 and a fraction of \-0.9.
.PP
The behavior of \fBmodf()\fR was changed to conform to the ANSI Standard.
