xref: /original-bsd/usr.bin/f77/libF77/d_mod.c (revision f72a1a16)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)d_mod.c	5.4	01/15/91
7  */
8 #ifdef tahoe
9 #include <tahoe/math/FP.h>
10 #endif
11 
12 double d_mod(x,y)
13 double *x, *y;
14 {
15 double floor(), quotient = *x / *y;
16 if (quotient >= 0.0)
17 	quotient = floor(quotient);
18 else {
19 #ifndef tahoe
20 	quotient = -floor(-quotient);
21 #else tahoe
22 	*(unsigned long *)&quotient ^= SIGN_BIT;
23 	quotient = floor(quotient);
24 	if (quotient !=0)
25 		*(unsigned long *)&quotient ^= SIGN_BIT;
26 #endif tahoe
27 }
28 return(*x - (*y) * quotient );
29 }
30