xref: /csrg-svn/usr.bin/f77/libF77/r_mod.c (revision 47940)
1*47940Sbostic /*-
2*47940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic  * All rights reserved.
422962Skre  *
5*47940Sbostic  * %sccs.include.proprietary.c%
610532Sdlw  */
710532Sdlw 
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)r_mod.c	5.6 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic 
1229969Smckusick #ifndef tahoe
1323856Sjerry float flt_retval;
1423856Sjerry 
r_mod(x,y)1523854Sjerry float r_mod(x,y)
1610532Sdlw float *x, *y;
1710532Sdlw {
1810532Sdlw double floor(), quotient = *x / *y;
1910532Sdlw if (quotient >= 0.0)
2010532Sdlw 	quotient = floor(quotient);
2110532Sdlw else
2210532Sdlw 	quotient = -floor(-quotient);
2323856Sjerry flt_retval = *x - (*y) * quotient ;
2423856Sjerry return(flt_retval);
2510532Sdlw }
2629969Smckusick 
2745967Sbostic #else
2829969Smckusick 
2929969Smckusick /*   THIS IS BASED ON THE TAHOE REPR. FOR FLOATING POINT */
3045967Sbostic #include <tahoe/math/FP.h>
3129969Smckusick 
r_mod(x,y)3229969Smckusick double r_mod(x,y)
3329969Smckusick float *x, *y;
3429969Smckusick {
3529969Smckusick double floor(), quotient = *x / *y;
3629969Smckusick if (quotient >= 0.0)
3729969Smckusick 	quotient = floor(quotient);
3829969Smckusick else {
3929969Smckusick 	*(unsigned long *)&quotient ^= SIGN_BIT;
4029969Smckusick 	quotient = floor(quotient);
4129969Smckusick 	if (quotient != 0)
4229969Smckusick 		*(unsigned long *)&quotient ^= SIGN_BIT;
4329969Smckusick 	}
4429969Smckusick return(*x - (*y) * quotient );
4529969Smckusick }
4645967Sbostic #endif
47