| 1 | /* |
| 2 | * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Oracle designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Oracle in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | * or visit www.oracle.com if you need additional information or have any |
| 23 | * questions. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * for non-zero x |
| 28 | * x = frexp(arg,&exp); |
| 29 | * return a double fp quantity x such that 0.5 <= |x| <1.0 |
| 30 | * and the corresponding binary exponent "exp". That is |
| 31 | * arg = x*2^exp. |
| 32 | * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg |
| 33 | * with *exp=0. |
| 34 | */ |
| 35 | |
| 36 | #include "fdlibm.h" |
| 37 | |
| 38 | #ifdef __STDC__ |
| 39 | static const double |
| 40 | #else |
| 41 | static double |
| 42 | #endif |
| 43 | two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ |
| 44 | |
| 45 | #ifdef __STDC__ |
| 46 | double frexp(double x, int *eptr) |
| 47 | #else |
| 48 | double frexp(x, eptr) |
| 49 | double x; int *eptr; |
| 50 | #endif |
| 51 | { |
| 52 | int hx, ix, lx; |
| 53 | hx = __HI(x); |
| 54 | ix = 0x7fffffff&hx; |
| 55 | lx = __LO(x); |
| 56 | *eptr = 0; |
| 57 | if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ |
| 58 | if (ix<0x00100000) { /* subnormal */ |
| 59 | x *= two54; |
| 60 | hx = __HI(x); |
| 61 | ix = hx&0x7fffffff; |
| 62 | *eptr = -54; |
| 63 | } |
| 64 | *eptr += (ix>>20)-1022; |
| 65 | hx = (hx&0x800fffff)|0x3fe00000; |
| 66 | __HI(x) = hx; |
| 67 | return x; |
| 68 | } |
| 69 | |