1 /* s_modff.c -- float version of s_modf.c. 2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 */ 4 5 /* 6 * ==================================================== 7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 * 9 * Developed at SunPro, a Sun Microsystems, Inc. business. 10 * Permission to use, copy, modify, and distribute this 11 * software is freely granted, provided that this notice 12 * is preserved. 13 * ==================================================== 14 */ 15 16 #include <sys/cdefs.h> 17 #if defined(LIBM_SCCS) && !defined(lint) 18 __RCSID("$NetBSD: s_modff.c,v 1.6 1999/07/02 15:37:43 simonb Exp $"); 19 #endif 20 21 #include "math.h" 22 #include "math_private.h" 23 24 #ifdef __STDC__ 25 static const float one = 1.0; 26 #else 27 static float one = 1.0; 28 #endif 29 30 #ifdef __STDC__ 31 float modff(float x, float *iptr) 32 #else 33 float modff(x, iptr) 34 float x,*iptr; 35 #endif 36 { 37 int32_t i0,j0; 38 u_int32_t i; 39 GET_FLOAT_WORD(i0,x); 40 j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */ 41 if(j0<23) { /* integer part in x */ 42 if(j0<0) { /* |x|<1 */ 43 SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */ 44 return x; 45 } else { 46 i = (0x007fffff)>>j0; 47 if((i0&i)==0) { /* x is integral */ 48 u_int32_t ix; 49 *iptr = x; 50 GET_FLOAT_WORD(ix,x); 51 SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ 52 return x; 53 } else { 54 SET_FLOAT_WORD(*iptr,i0&(~i)); 55 return x - *iptr; 56 } 57 } 58 } else { /* no fraction part */ 59 u_int32_t ix; 60 *iptr = x*one; 61 GET_FLOAT_WORD(ix,x); 62 SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ 63 return x; 64 } 65 } 66