comparison tests/testincludes/std/IEEE.d @ 1595:628433c343b4

Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}. Updated the runtest script to build libtangobos-partial.a if it hasn't already been built. Added in signbit() and va_arg!()() to libtangobos-partial.a so more of the phobos dependent DStress tests pass.
author Robert Clipsham <robert@octarineparrot.com>
date Sun, 08 Nov 2009 16:16:17 +0000
parents
children
comparison
equal deleted inserted replaced
1594:9f7151d890ff 1595:628433c343b4
1 // Written in the D programming language
2 /*
3 * Authors:
4 * Walter Bright, Don Clugston
5 * Copyright:
6 * Copyright (c) 2001-2005 by Digital Mars,
7 * All Rights Reserved,
8 * www.digitalmars.com
9 * License:
10 * This software is provided 'as-is', without any express or implied
11 * warranty. In no event will the authors be held liable for any damages
12 * arising from the use of this software.
13 *
14 * Permission is granted to anyone to use this software for any purpose,
15 * including commercial applications, and to alter it and redistribute it
16 * freely, subject to the following restrictions:
17 *
18 * <ul>
19 * <li> The origin of this software must not be misrepresented; you must not
20 * claim that you wrote the original software. If you use this software
21 * in a product, an acknowledgment in the product documentation would be
22 * appreciated but is not required.
23 * </li>
24 * <li> Altered source versions must be plainly marked as such, and must not
25 * be misrepresented as being the original software.
26 * </li>
27 * <li> This notice may not be removed or altered from any source
28 * distribution.
29 * </li>
30 * </ul>
31 */
32 /* Cut down version for libtangobos-partial/dstress */
33
34 module tango.math.IEEE;
35
36
37 private:
38 /*
39 * The following IEEE 'real' formats are currently supported:
40 * 64 bit Big-endian 'double' (eg PowerPC)
41 * 128 bit Big-endian 'quadruple' (eg SPARC)
42 * 64 bit Little-endian 'double' (eg x86-SSE2)
43 * 80 bit Little-endian, with implied bit 'real80' (eg x87, Itanium).
44 * 128 bit Little-endian 'quadruple' (not implemented on any known processor!)
45 *
46 * Non-IEEE 128 bit Big-endian 'doubledouble' (eg PowerPC) has partial support
47 */
48 version(LittleEndian) {
49 static assert(real.mant_dig == 53 || real.mant_dig==64
50 || real.mant_dig == 113,
51 "Only 64-bit, 80-bit, and 128-bit reals"
52 " are supported for LittleEndian CPUs");
53 } else {
54 static assert(real.mant_dig == 53 || real.mant_dig==106
55 || real.mant_dig == 113,
56 "Only 64-bit and 128-bit reals are supported for BigEndian CPUs."
57 " double-double reals have partial support");
58 }
59
60 // Constants used for extracting the components of the representation.
61 // They supplement the built-in floating point properties.
62 template floatTraits(T) {
63 // EXPMASK is a ushort mask to select the exponent portion (without sign)
64 // POW2MANTDIG = pow(2, real.mant_dig) is the value such that
65 // (smallest_denormal)*POW2MANTDIG == real.min
66 // EXPPOS_SHORT is the index of the exponent when represented as a ushort array.
67 // SIGNPOS_BYTE is the index of the sign when represented as a ubyte array.
68 static if (T.mant_dig == 24) { // float
69 const ushort EXPMASK = 0x7F80;
70 const ushort EXPBIAS = 0x3F00;
71 const uint EXPMASK_INT = 0x7F80_0000;
72 const uint MANTISSAMASK_INT = 0x007F_FFFF;
73 const real POW2MANTDIG = 0x1p+24;
74 version(LittleEndian) {
75 const EXPPOS_SHORT = 1;
76 } else {
77 const EXPPOS_SHORT = 0;
78 }
79 } else static if (T.mant_dig == 53) { // double, or real==double
80 const ushort EXPMASK = 0x7FF0;
81 const ushort EXPBIAS = 0x3FE0;
82 const uint EXPMASK_INT = 0x7FF0_0000;
83 const uint MANTISSAMASK_INT = 0x000F_FFFF; // for the MSB only
84 const real POW2MANTDIG = 0x1p+53;
85 version(LittleEndian) {
86 const EXPPOS_SHORT = 3;
87 const SIGNPOS_BYTE = 7;
88 } else {
89 const EXPPOS_SHORT = 0;
90 const SIGNPOS_BYTE = 0;
91 }
92 } else static if (T.mant_dig == 64) { // real80
93 const ushort EXPMASK = 0x7FFF;
94 const ushort EXPBIAS = 0x3FFE;
95 const real POW2MANTDIG = 0x1p+63;
96 version(LittleEndian) {
97 const EXPPOS_SHORT = 4;
98 const SIGNPOS_BYTE = 9;
99 } else {
100 const EXPPOS_SHORT = 0;
101 const SIGNPOS_BYTE = 0;
102 }
103 } else static if (real.mant_dig == 113){ // quadruple
104 const ushort EXPMASK = 0x7FFF;
105 const real POW2MANTDIG = 0x1p+113;
106 version(LittleEndian) {
107 const EXPPOS_SHORT = 7;
108 const SIGNPOS_BYTE = 15;
109 } else {
110 const EXPPOS_SHORT = 0;
111 const SIGNPOS_BYTE = 0;
112 }
113 } else static if (real.mant_dig == 106) { // doubledouble
114 const ushort EXPMASK = 0x7FF0;
115 const real POW2MANTDIG = 0x1p+53; // doubledouble denormals are strange
116 // and the exponent byte is not unique
117 version(LittleEndian) {
118 const EXPPOS_SHORT = 7; // [3] is also an exp short
119 const SIGNPOS_BYTE = 15;
120 } else {
121 const EXPPOS_SHORT = 0; // [4] is also an exp short
122 const SIGNPOS_BYTE = 0;
123 }
124 }
125 }
126
127
128 public:
129 /*********************************
130 * Return 1 if sign bit of e is set, 0 if not.
131 */
132
133 int signbit(real x)
134 {
135 return ((cast(ubyte *)&x)[floatTraits!(real).SIGNPOS_BYTE] & 0x80) != 0;
136 }