#include "SDL_internal.h"1/*2* ====================================================3* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.4*5* Developed at SunPro, a Sun Microsystems, Inc. business.6* Permission to use, copy, modify, and distribute this7* software is freely granted, provided that this notice8* is preserved.9* ====================================================10*/1112/*13* modf(double x, double *iptr)14* return fraction part of x, and return x's integral part in *iptr.15* Method:16* Bit twiddling.17*18* Exception:19* No exception.20*/2122#include "math_libm.h"23#include "math_private.h"2425static const double one = 1.0;2627double modf(double x, double *iptr)28{29int32_t i0,i1,_j0;30u_int32_t i;31EXTRACT_WORDS(i0,i1,x);32_j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */33if(_j0<20) { /* integer part in high x */34if(_j0<0) { /* |x|<1 */35INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */36return x;37} else {38i = (0x000fffff)>>_j0;39if(((i0&i)|i1)==0) { /* x is integral */40*iptr = x;41INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */42return x;43} else {44INSERT_WORDS(*iptr,i0&(~i),0);45return x - *iptr;46}47}48} else if (_j0>51) { /* no fraction part */49*iptr = x*one;50/* We must handle NaNs separately. */51if (_j0 == 0x400 && ((i0 & 0xfffff) | i1))52return x*one;53INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */54return x;55} else { /* fraction part in low x */56i = ((u_int32_t)(0xffffffff))>>(_j0-20);57if((i1&i)==0) { /* x is integral */58*iptr = x;59INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */60return x;61} else {62INSERT_WORDS(*iptr,i0,i1&(~i));63return x - *iptr;64}65}66}67libm_hidden_def(modf)686970