]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /* $NetBSD: ulp.c,v 1.2 2006/01/25 15:27:42 kleink Exp $ */\r |
2 | \r | |
3 | /****************************************************************\r | |
4 | \r | |
5 | The author of this software is David M. Gay.\r | |
6 | \r | |
7 | Copyright (C) 1998, 1999 by Lucent Technologies\r | |
8 | All Rights Reserved\r | |
9 | \r | |
10 | Permission to use, copy, modify, and distribute this software and\r | |
11 | its documentation for any purpose and without fee is hereby\r | |
12 | granted, provided that the above copyright notice appear in all\r | |
13 | copies and that both that the copyright notice and this\r | |
14 | permission notice and warranty disclaimer appear in supporting\r | |
15 | documentation, and that the name of Lucent or any of its entities\r | |
16 | not be used in advertising or publicity pertaining to\r | |
17 | distribution of the software without specific, written prior\r | |
18 | permission.\r | |
19 | \r | |
20 | LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,\r | |
21 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.\r | |
22 | IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY\r | |
23 | SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r | |
24 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\r | |
25 | IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,\r | |
26 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\r | |
27 | THIS SOFTWARE.\r | |
28 | \r | |
29 | ****************************************************************/\r | |
30 | \r | |
31 | /* Please send bug reports to David M. Gay (dmg at acm dot org,\r | |
32 | * with " at " changed at "@" and " dot " changed to "."). */\r | |
33 | #include <LibConfig.h>\r | |
34 | \r | |
35 | #include "gdtoaimp.h"\r | |
36 | \r | |
37 | double\r | |
38 | ulp\r | |
39 | #ifdef KR_headers\r | |
40 | (x) double x;\r | |
41 | #else\r | |
42 | (double x)\r | |
43 | #endif\r | |
44 | {\r | |
45 | Long L;\r | |
46 | double a;\r | |
47 | \r | |
48 | L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;\r | |
49 | #ifndef Sudden_Underflow\r | |
50 | if (L > 0) {\r | |
51 | #endif\r | |
52 | #ifdef IBM\r | |
53 | L |= Exp_msk1 >> 4;\r | |
54 | #endif\r | |
55 | word0(a) = (UINT32)L;\r | |
56 | word1(a) = 0;\r | |
57 | #ifndef Sudden_Underflow\r | |
58 | }\r | |
59 | else {\r | |
60 | L = (unsigned int)-L >> Exp_shift;\r | |
61 | if (L < Exp_shift) {\r | |
62 | word0(a) = 0x80000 >> L;\r | |
63 | word1(a) = 0;\r | |
64 | }\r | |
65 | else {\r | |
66 | word0(a) = 0;\r | |
67 | L -= Exp_shift;\r | |
68 | word1(a) = L >= 31 ? 1 : 1 << (31 - L);\r | |
69 | }\r | |
70 | }\r | |
71 | #endif\r | |
72 | return a;\r | |
73 | }\r |