Back to index

glibc  2.9
s_modff.c
Go to the documentation of this file.
00001 /* s_modff.c -- float version of s_modf.c.
00002  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 #if defined(LIBM_SCCS) && !defined(lint)
00017 static char rcsid[] = "$NetBSD: s_modff.c,v 1.4 1995/05/10 20:47:56 jtc Exp $";
00018 #endif
00019 
00020 #include "math.h"
00021 #include "math_private.h"
00022 
00023 #ifdef __STDC__
00024 static const float one = 1.0;
00025 #else
00026 static float one = 1.0;
00027 #endif
00028 
00029 #ifdef __STDC__
00030        float __modff(float x, float *iptr)
00031 #else
00032        float __modff(x, iptr)
00033        float x,*iptr;
00034 #endif
00035 {
00036        int32_t i0,j0;
00037        u_int32_t i;
00038        GET_FLOAT_WORD(i0,x);
00039        j0 = ((i0>>23)&0xff)-0x7f;  /* exponent of x */
00040        if(j0<23) {                 /* integer part in x */
00041            if(j0<0) {                     /* |x|<1 */
00042                SET_FLOAT_WORD(*iptr,i0&0x80000000);     /* *iptr = +-0 */
00043               return x;
00044            } else {
00045               i = (0x007fffff)>>j0;
00046               if((i0&i)==0) {                    /* x is integral */
00047                   u_int32_t ix;
00048                   *iptr = x;
00049                   GET_FLOAT_WORD(ix,x);
00050                   SET_FLOAT_WORD(x,ix&0x80000000);      /* return +-0 */
00051                   return x;
00052               } else {
00053                   SET_FLOAT_WORD(*iptr,i0&(~i));
00054                   return x - *iptr;
00055               }
00056            }
00057        } else {                    /* no fraction part */
00058            *iptr = x*one;
00059            /* We must handle NaNs separately.  */
00060            if (j0 == 0x80 && (i0 & 0x7fffff))
00061              return x*one;
00062            SET_FLOAT_WORD(x,i0&0x80000000);      /* return +-0 */
00063            return x;
00064        }
00065 }
00066 weak_alias (__modff, modff)