Path: blob/master/src/java.base/share/native/libfdlibm/s_modf.c
41149 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* modf(double x, double *iptr)27* return fraction part of x, and return x's integral part in *iptr.28* Method:29* Bit twiddling.30*31* Exception:32* No exception.33*/3435#include "fdlibm.h"3637#ifdef __STDC__38static const double one = 1.0;39#else40static double one = 1.0;41#endif4243#ifdef __STDC__44double modf(double x, double *iptr)45#else46double modf(x, iptr)47double x,*iptr;48#endif49{50int i0,i1,j0;51unsigned i;52i0 = __HI(x); /* high x */53i1 = __LO(x); /* low x */54j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */55if(j0<20) { /* integer part in high x */56if(j0<0) { /* |x|<1 */57__HIp(iptr) = i0&0x80000000;58__LOp(iptr) = 0; /* *iptr = +-0 */59return x;60} else {61i = (0x000fffff)>>j0;62if(((i0&i)|i1)==0) { /* x is integral */63*iptr = x;64__HI(x) &= 0x80000000;65__LO(x) = 0; /* return +-0 */66return x;67} else {68__HIp(iptr) = i0&(~i);69__LOp(iptr) = 0;70return x - *iptr;71}72}73} else if (j0>51) { /* no fraction part */74*iptr = x*one;75__HI(x) &= 0x80000000;76__LO(x) = 0; /* return +-0 */77return x;78} else { /* fraction part in low x */79i = ((unsigned)(0xffffffff))>>(j0-20);80if((i1&i)==0) { /* x is integral */81*iptr = x;82__HI(x) &= 0x80000000;83__LO(x) = 0; /* return +-0 */84return x;85} else {86__HIp(iptr) = i0;87__LOp(iptr) = i1&(~i);88return x - *iptr;89}90}91}929394