Path: blob/master/src/java.base/share/native/libfdlibm/s_frexp.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* for non-zero x27* x = frexp(arg,&exp);28* return a double fp quantity x such that 0.5 <= |x| <1.029* and the corresponding binary exponent "exp". That is30* arg = x*2^exp.31* If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg32* with *exp=0.33*/3435#include "fdlibm.h"3637#ifdef __STDC__38static const double39#else40static double41#endif42two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */4344#ifdef __STDC__45double frexp(double x, int *eptr)46#else47double frexp(x, eptr)48double x; int *eptr;49#endif50{51int hx, ix, lx;52hx = __HI(x);53ix = 0x7fffffff&hx;54lx = __LO(x);55*eptr = 0;56if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */57if (ix<0x00100000) { /* subnormal */58x *= two54;59hx = __HI(x);60ix = hx&0x7fffffff;61*eptr = -54;62}63*eptr += (ix>>20)-1022;64hx = (hx&0x800fffff)|0x3fe00000;65__HI(x) = hx;66return x;67}686970