1 | /* s_frexpl.c -- long double version of s_frexp.c. |
2 | * Conversion to long double by Ulrich Drepper, |
3 | * Cygnus Support, drepper@cygnus.com. |
4 | */ |
5 | |
6 | /* |
7 | * ==================================================== |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
9 | * |
10 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
11 | * Permission to use, copy, modify, and distribute this |
12 | * software is freely granted, provided that this notice |
13 | * is preserved. |
14 | * ==================================================== |
15 | */ |
16 | |
17 | #if defined(LIBM_SCCS) && !defined(lint) |
18 | static char rcsid[] = "$NetBSD: $" ; |
19 | #endif |
20 | |
21 | /* |
22 | * for non-zero x |
23 | * x = frexpl(arg,&exp); |
24 | * return a long double fp quantity x such that 0.5 <= |x| <1.0 |
25 | * and the corresponding binary exponent "exp". That is |
26 | * arg = x*2^exp. |
27 | * If arg is inf, 0.0, or NaN, then frexpl(arg,&exp) returns arg |
28 | * with *exp=0. |
29 | */ |
30 | |
31 | #include <float.h> |
32 | #include <math.h> |
33 | #include <math_private.h> |
34 | #include <libm-alias-ldouble.h> |
35 | |
36 | static const long double |
37 | #if LDBL_MANT_DIG == 64 |
38 | two65 = 3.68934881474191032320e+19L; /* 0x4040, 0x80000000, 0x00000000 */ |
39 | #else |
40 | # error "Cannot handle this MANT_DIG" |
41 | #endif |
42 | |
43 | |
44 | long double __frexpl(long double x, int *eptr) |
45 | { |
46 | uint32_t se, hx, ix, lx; |
47 | GET_LDOUBLE_WORDS(se,hx,lx,x); |
48 | ix = 0x7fff&se; |
49 | *eptr = 0; |
50 | if(ix==0x7fff||((ix|hx|lx)==0)) return x + x; /* 0,inf,nan */ |
51 | if (ix==0x0000) { /* subnormal */ |
52 | x *= two65; |
53 | GET_LDOUBLE_EXP(se,x); |
54 | ix = se&0x7fff; |
55 | *eptr = -65; |
56 | } |
57 | *eptr += ix-16382; |
58 | se = (se & 0x8000) | 0x3ffe; |
59 | SET_LDOUBLE_EXP(x,se); |
60 | return x; |
61 | } |
62 | libm_alias_ldouble (__frexp, frexp) |
63 | |