]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Math/s_modf.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / LibC / Math / s_modf.c
CommitLineData
2aa62f2b 1/* @(#)s_modf.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_modf.c,v 1.11 2002/05/26 22:01:57 wiz Exp $");\r
16#endif\r
17\r
18/*\r
19 * modf(double x, double *iptr)\r
20 * return fraction part of x, and return x's integral part in *iptr.\r
21 * Method:\r
22 * Bit twiddling.\r
23 *\r
24 * Exception:\r
25 * No exception.\r
26 */\r
27\r
28#include "math.h"\r
29#include "math_private.h"\r
30\r
31static const double one = 1.0;\r
32\r
33double\r
34modf(double x, double *iptr)\r
35{\r
36 int32_t i0,i1,j0;\r
37 u_int32_t i;\r
38 EXTRACT_WORDS(i0,i1,x);\r
39 j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */\r
40 if(j0<20) { /* integer part in high x */\r
41 if(j0<0) { /* |x|<1 */\r
42 INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */\r
43 return x;\r
44 } else {\r
45 i = (0x000fffff)>>j0;\r
46 if(((i0&i)|i1)==0) { /* x is integral */\r
47 u_int32_t high;\r
48 *iptr = x;\r
49 GET_HIGH_WORD(high,x);\r
50 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */\r
51 return x;\r
52 } else {\r
53 INSERT_WORDS(*iptr,i0&(~i),0);\r
54 return x - *iptr;\r
55 }\r
56 }\r
57 } else if (j0>51) { /* no fraction part */\r
58 u_int32_t high;\r
59 *iptr = x*one;\r
60 GET_HIGH_WORD(high,x);\r
61 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */\r
62 return x;\r
63 } else { /* fraction part in low x */\r
64 i = ((u_int32_t)(0xffffffff))>>(j0-20);\r
65 if((i1&i)==0) { /* x is integral */\r
66 u_int32_t high;\r
67 *iptr = x;\r
68 GET_HIGH_WORD(high,x);\r
69 INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */\r
70 return x;\r
71 } else {\r
72 INSERT_WORDS(*iptr,i0,i1&(~i));\r
73 return x - *iptr;\r
74 }\r
75 }\r
76}\r