]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Math/s_frexp.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / LibC / Math / s_frexp.c
CommitLineData
2aa62f2b 1/* @(#)s_frexp.c 5.1 93/09/24 */\r
2/*\r
3 * ====================================================\r
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r
5 *\r
6 * Developed at SunPro, a Sun Microsystems, Inc. business.\r
7 * Permission to use, copy, modify, and distribute this\r
8 * software is freely granted, provided that this notice\r
9 * is preserved.\r
10 * ====================================================\r
11 */\r
12#include <LibConfig.h>\r
13#include <sys/EfiCdefs.h>\r
14#if defined(LIBM_SCCS) && !defined(lint)\r
15__RCSID("$NetBSD: s_frexp.c,v 1.12 2002/05/26 22:01:56 wiz Exp $");\r
16#endif\r
17\r
18/*\r
19 * for non-zero x\r
20 * x = frexp(arg,&exp);\r
21 * return a double fp quantity x such that 0.5 <= |x| <1.0\r
22 * and the corresponding binary exponent "exp". That is\r
23 * arg = x*2^exp.\r
24 * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg\r
25 * with *exp=0.\r
26 */\r
27\r
28#include "math.h"\r
29#include "math_private.h"\r
30\r
31static const double\r
32two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */\r
33\r
34double\r
35frexp(double x, int *eptr)\r
36{\r
37 int32_t hx, ix, lx;\r
38 EXTRACT_WORDS(hx,lx,x);\r
39 ix = 0x7fffffff&hx;\r
40 *eptr = 0;\r
41 if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */\r
42 if (ix<0x00100000) { /* subnormal */\r
43 x *= two54;\r
44 GET_HIGH_WORD(hx,x);\r
45 ix = hx&0x7fffffff;\r
46 *eptr = -54;\r
47 }\r
48 *eptr += (ix>>20)-1022;\r
49 hx = (hx&0x800fffff)|0x3fe00000;\r
50 SET_HIGH_WORD(x,hx);\r
51 return x;\r
52}\r