|
Packit |
6c4009 |
/* s_modff.c -- float version of s_modf.c.
|
|
Packit |
6c4009 |
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
#include <libm-alias-float.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const float one = 1.0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
float
|
|
Packit |
6c4009 |
__modff(float x, float *iptr)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int32_t i0,j0;
|
|
Packit |
6c4009 |
uint32_t i;
|
|
Packit |
6c4009 |
GET_FLOAT_WORD(i0,x);
|
|
Packit |
6c4009 |
j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */
|
|
Packit |
6c4009 |
if(__builtin_expect(j0<23, 1)) { /* integer part in x */
|
|
Packit |
6c4009 |
if(j0<0) { /* |x|<1 */
|
|
Packit |
6c4009 |
SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
} else {
|
|
Packit |
6c4009 |
i = (0x007fffff)>>j0;
|
|
Packit |
6c4009 |
if((i0&i)==0) { /* x is integral */
|
|
Packit |
6c4009 |
uint32_t ix;
|
|
Packit |
6c4009 |
*iptr = x;
|
|
Packit |
6c4009 |
GET_FLOAT_WORD(ix,x);
|
|
Packit |
6c4009 |
SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
} else {
|
|
Packit |
6c4009 |
SET_FLOAT_WORD(*iptr,i0&(~i));
|
|
Packit |
6c4009 |
return x - *iptr;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
} else { /* no fraction part */
|
|
Packit |
6c4009 |
*iptr = x*one;
|
|
Packit |
6c4009 |
/* We must handle NaNs separately. */
|
|
Packit |
6c4009 |
if (j0 == 0x80 && (i0 & 0x7fffff))
|
|
Packit |
6c4009 |
return x*one;
|
|
Packit |
6c4009 |
SET_FLOAT_WORD(x,i0&0x80000000); /* return +-0 */
|
|
Packit |
6c4009 |
return x;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
libm_alias_float (__modf, modf)
|