date and time created 90/04/23 19:57:05 by william
[unix-history] / usr / src / lib / libc / i386 / gen / modf.s
CommitLineData
91073d83
WN
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sean Eric Fagan
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
12static char sccsid[] = "@(#)modf.s 5.1 (Berkeley) %G%";
13#endif /* LIBC_SCCS and not lint */
14
15/*
16 * modf(value, iptr): return fractional part of value, and stores the
17 * integral part into iptr (a pointer to double).
18 *
19 * Written by Sean Eric Fagan (sef@kithrup.COM)
20 * Sun Mar 11 20:27:30 PST 1990
21 */
22
23/* With CHOP mode on, frndint behaves as TRUNC does. Useful. */
24double
25modf(double value, double *iptr)
26{
27 double temp;
28 short i87flag, i87temp;
29 __asm ("fnstcw %0" : "=g" (i87flag) : );
30 i87temp = i87flag | 0xc00 ; /* turn on chop mode [truncation] */
31 __asm ("fldcw %0" : : "g" (i87temp));
32 __asm ("frndint" : "=f" (temp) : "0" (value)); /* temp = int of value */
33 __asm ("fldcw %0" : : "g" (i87flag));
34 *iptr = temp;
35 return (value - temp);
36}