SCM Repository
Annotation of /sml/branches/SMLNJ/src/compiler/MiscUtil/bignums/ieeereal.sml
Parent Directory
|
Revision Log
Revision 221 -
(view)
(download)
Original Path: sml/trunk/src/compiler/MiscUtil/bignums/ieeereal.sml
1 : | monnier | 221 | (* Copyright 1989 by AT&T Bell Laboratories |
2 : | * | ||
3 : | *) | ||
4 : | (* Support for IEEE floating-point constants | ||
5 : | * Double precision format (for normalized numbers): | ||
6 : | * Bias = 1023. | ||
7 : | * Exponent = 11 bits. | ||
8 : | * Range of exponent = [1..2046] | ||
9 : | * Mantissa = 52 (+1) bits. | ||
10 : | * Value = (-1)^s * 2^(e-1023) * 1.f | ||
11 : | *) | ||
12 : | structure IEEERealConst = RealConst( | ||
13 : | struct | ||
14 : | val significant = 53 (* 52 + redundant 1 bit *) | ||
15 : | val minexp = ~1021 and maxexp = 1024 | ||
16 : | val itow = Word.fromInt | ||
17 : | val wtoi = Word.toIntX | ||
18 : | |||
19 : | fun transreal (sign, frac, exp) = | ||
20 : | if frac(0,1)=0 | ||
21 : | then if sign=0 then "\000\000\000\000\000\000\000\000" | ||
22 : | else "\128\000\000\000\000\000\000\000" | ||
23 : | else implode | ||
24 : | [Char.chr(wtoi | ||
25 : | (Word.orb(Word.<<(itow sign, 0w7), | ||
26 : | Word.>>(itow(exp+1022), 0w4)))), | ||
27 : | Char.chr(wtoi | ||
28 : | (Word.andb(0w255, | ||
29 : | Word.orb(Word.<<(itow(exp+1022), 0w4), | ||
30 : | itow (frac(1,4)))))), | ||
31 : | Char.chr(frac(5,8)), | ||
32 : | Char.chr(frac(13,8)), | ||
33 : | Char.chr(frac(21,8)), | ||
34 : | Char.chr(frac(29,8)), | ||
35 : | Char.chr(frac(37,8)), | ||
36 : | Char.chr(frac(45,8))] | ||
37 : | |||
38 : | end) | ||
39 : | |||
40 : | (* | ||
41 : | * $Log: ieeereal.sml,v $ | ||
42 : | * Revision 1.1 1998/10/28 18:22:32 jhr | ||
43 : | * Moved from OldCGen. | ||
44 : | * | ||
45 : | * Revision 1.1.1.1 1998/04/08 18:39:49 george | ||
46 : | * Version 110.5 | ||
47 : | * | ||
48 : | *) |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |