1 /* $OpenBSD: const.c,v 1.1 2011/05/30 20:23:35 martynas Exp $ */ 2 3 /* 4 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /* const.c 20 * 21 * Globally declared constants 22 * 23 * 24 * 25 * SYNOPSIS: 26 * 27 * extern double nameofconstant; 28 * 29 * 30 * 31 * 32 * DESCRIPTION: 33 * 34 * This file contains a number of mathematical constants and 35 * also some needed size parameters of the computer arithmetic. 36 * The values are supplied as arrays of hexadecimal integers 37 * for IEEE arithmetic; arrays of octal constants for DEC 38 * arithmetic; and in a normal decimal scientific notation for 39 * other machines. The particular notation used is determined 40 * by a symbol (DEC, IBMPC, or UNK) defined in the include file 41 * mconf.h. 42 * 43 * The default size parameters are as follows. 44 * 45 * For DEC and UNK modes: 46 * MACHEP = 1.38777878078144567553E-17 2**-56 47 * MAXLOG = 8.8029691931113054295988E1 log(2**127) 48 * MINLOG = -8.872283911167299960540E1 log(2**-128) 49 * MAXNUM = 1.701411834604692317316873e38 2**127 50 * 51 * For IEEE arithmetic (IBMPC): 52 * MACHEP = 1.11022302462515654042E-16 2**-53 53 * MAXLOG = 7.09782712893383996843E2 log(2**1024) 54 * MINLOG = -7.08396418532264106224E2 log(2**-1022) 55 * MAXNUM = 1.7976931348623158E308 2**1024 56 * 57 * The global symbols for mathematical constants are 58 * PI = 3.14159265358979323846 pi 59 * PIO2 = 1.57079632679489661923 pi/2 60 * PIO4 = 7.85398163397448309616E-1 pi/4 61 * SQRT2 = 1.41421356237309504880 sqrt(2) 62 * SQRTH = 7.07106781186547524401E-1 sqrt(2)/2 63 * LOG2E = 1.4426950408889634073599 1/log(2) 64 * SQ2OPI = 7.9788456080286535587989E-1 sqrt( 2/pi ) 65 * LOGE2 = 6.93147180559945309417E-1 log(2) 66 * LOGSQ2 = 3.46573590279972654709E-1 log(2)/2 67 * THPIO4 = 2.35619449019234492885 3*pi/4 68 * TWOOPI = 6.36619772367581343075535E-1 2/pi 69 * 70 * These lists are subject to change. 71 */ 72 73 #include "mconf.h" 74 75 #ifdef UNK 76 #if 1 77 double MACHEP = 1.11022302462515654042E-16; /* 2**-53 */ 78 #else 79 double MACHEP = 1.38777878078144567553E-17; /* 2**-56 */ 80 #endif 81 double UFLOWTHRESH = 2.22507385850720138309E-308; /* 2**-1022 */ 82 #ifdef DENORMAL 83 double MAXLOG = 7.09782712893383996732E2; /* log(MAXNUM) */ 84 /* double MINLOG = -7.44440071921381262314E2; */ /* log(2**-1074) */ 85 double MINLOG = -7.451332191019412076235E2; /* log(2**-1075) */ 86 #else 87 double MAXLOG = 7.08396418532264106224E2; /* log 2**1022 */ 88 double MINLOG = -7.08396418532264106224E2; /* log 2**-1022 */ 89 #endif 90 double MAXNUM = 1.79769313486231570815E308; /* 2**1024*(1-MACHEP) */ 91 double PI = 3.14159265358979323846; /* pi */ 92 double PIO2 = 1.57079632679489661923; /* pi/2 */ 93 double PIO4 = 7.85398163397448309616E-1; /* pi/4 */ 94 double SQRT2 = 1.41421356237309504880; /* sqrt(2) */ 95 double SQRTH = 7.07106781186547524401E-1; /* sqrt(2)/2 */ 96 double LOG2E = 1.4426950408889634073599; /* 1/log(2) */ 97 double SQ2OPI = 7.9788456080286535587989E-1; /* sqrt( 2/pi ) */ 98 double LOGE2 = 6.93147180559945309417E-1; /* log(2) */ 99 double LOGSQ2 = 3.46573590279972654709E-1; /* log(2)/2 */ 100 double THPIO4 = 2.35619449019234492885; /* 3*pi/4 */ 101 double TWOOPI = 6.36619772367581343075535E-1; /* 2/pi */ 102 #ifdef INFINITIES 103 double INFINITY = 1.0/0.0; /* 99e999; */ 104 #else 105 double INFINITY = 1.79769313486231570815E308; /* 2**1024*(1-MACHEP) */ 106 #endif 107 #ifdef NANS 108 double NAN = 1.0/0.0 - 1.0/0.0; 109 #else 110 double NAN = 0.0; 111 #endif 112 #ifdef MINUSZERO 113 double NEGZERO = -0.0; 114 #else 115 double NEGZERO = 0.0; 116 #endif 117 #endif 118 119 #ifdef IBMPC 120 /* 2**-53 = 1.11022302462515654042E-16 */ 121 unsigned short MACHEP[4] = {0x0000,0x0000,0x0000,0x3ca0}; 122 unsigned short UFLOWTHRESH[4] = {0x0000,0x0000,0x0000,0x0010}; 123 #ifdef DENORMAL 124 /* log(MAXNUM) = 7.09782712893383996732224E2 */ 125 unsigned short MAXLOG[4] = {0x39ef,0xfefa,0x2e42,0x4086}; 126 /* log(2**-1074) = - -7.44440071921381262314E2 */ 127 /*unsigned short MINLOG[4] = {0x71c3,0x446d,0x4385,0xc087};*/ 128 unsigned short MINLOG[4] = {0x3052,0xd52d,0x4910,0xc087}; 129 #else 130 /* log(2**1022) = 7.08396418532264106224E2 */ 131 unsigned short MAXLOG[4] = {0xbcd2,0xdd7a,0x232b,0x4086}; 132 /* log(2**-1022) = - 7.08396418532264106224E2 */ 133 unsigned short MINLOG[4] = {0xbcd2,0xdd7a,0x232b,0xc086}; 134 #endif 135 /* 2**1024*(1-MACHEP) = 1.7976931348623158E308 */ 136 unsigned short MAXNUM[4] = {0xffff,0xffff,0xffff,0x7fef}; 137 unsigned short PI[4] = {0x2d18,0x5444,0x21fb,0x4009}; 138 unsigned short PIO2[4] = {0x2d18,0x5444,0x21fb,0x3ff9}; 139 unsigned short PIO4[4] = {0x2d18,0x5444,0x21fb,0x3fe9}; 140 unsigned short SQRT2[4] = {0x3bcd,0x667f,0xa09e,0x3ff6}; 141 unsigned short SQRTH[4] = {0x3bcd,0x667f,0xa09e,0x3fe6}; 142 unsigned short LOG2E[4] = {0x82fe,0x652b,0x1547,0x3ff7}; 143 unsigned short SQ2OPI[4] = {0x3651,0x33d4,0x8845,0x3fe9}; 144 unsigned short LOGE2[4] = {0x39ef,0xfefa,0x2e42,0x3fe6}; 145 unsigned short LOGSQ2[4] = {0x39ef,0xfefa,0x2e42,0x3fd6}; 146 unsigned short THPIO4[4] = {0x21d2,0x7f33,0xd97c,0x4002}; 147 unsigned short TWOOPI[4] = {0xc883,0x6dc9,0x5f30,0x3fe4}; 148 #ifdef INFINITIES 149 unsigned short INFINITY[4] = {0x0000,0x0000,0x0000,0x7ff0}; 150 #else 151 unsigned short INFINITY[4] = {0xffff,0xffff,0xffff,0x7fef}; 152 #endif 153 #ifdef NANS 154 unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x7ffc}; 155 #else 156 unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x0000}; 157 #endif 158 #ifdef MINUSZERO 159 unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x8000}; 160 #else 161 unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x0000}; 162 #endif 163 #endif 164 165 #ifdef MIEEE 166 /* 2**-53 = 1.11022302462515654042E-16 */ 167 unsigned short MACHEP[4] = {0x3ca0,0x0000,0x0000,0x0000}; 168 unsigned short UFLOWTHRESH[4] = {0x0010,0x0000,0x0000,0x0000}; 169 #ifdef DENORMAL 170 /* log(2**1024) = 7.09782712893383996843E2 */ 171 unsigned short MAXLOG[4] = {0x4086,0x2e42,0xfefa,0x39ef}; 172 /* log(2**-1074) = - -7.44440071921381262314E2 */ 173 /* unsigned short MINLOG[4] = {0xc087,0x4385,0x446d,0x71c3}; */ 174 unsigned short MINLOG[4] = {0xc087,0x4910,0xd52d,0x3052}; 175 #else 176 /* log(2**1022) = 7.08396418532264106224E2 */ 177 unsigned short MAXLOG[4] = {0x4086,0x232b,0xdd7a,0xbcd2}; 178 /* log(2**-1022) = - 7.08396418532264106224E2 */ 179 unsigned short MINLOG[4] = {0xc086,0x232b,0xdd7a,0xbcd2}; 180 #endif 181 /* 2**1024*(1-MACHEP) = 1.7976931348623158E308 */ 182 unsigned short MAXNUM[4] = {0x7fef,0xffff,0xffff,0xffff}; 183 unsigned short PI[4] = {0x4009,0x21fb,0x5444,0x2d18}; 184 unsigned short PIO2[4] = {0x3ff9,0x21fb,0x5444,0x2d18}; 185 unsigned short PIO4[4] = {0x3fe9,0x21fb,0x5444,0x2d18}; 186 unsigned short SQRT2[4] = {0x3ff6,0xa09e,0x667f,0x3bcd}; 187 unsigned short SQRTH[4] = {0x3fe6,0xa09e,0x667f,0x3bcd}; 188 unsigned short LOG2E[4] = {0x3ff7,0x1547,0x652b,0x82fe}; 189 unsigned short SQ2OPI[4] = {0x3fe9,0x8845,0x33d4,0x3651}; 190 unsigned short LOGE2[4] = {0x3fe6,0x2e42,0xfefa,0x39ef}; 191 unsigned short LOGSQ2[4] = {0x3fd6,0x2e42,0xfefa,0x39ef}; 192 unsigned short THPIO4[4] = {0x4002,0xd97c,0x7f33,0x21d2}; 193 unsigned short TWOOPI[4] = {0x3fe4,0x5f30,0x6dc9,0xc883}; 194 #ifdef INFINITIES 195 unsigned short INFINITY[4] = {0x7ff0,0x0000,0x0000,0x0000}; 196 #else 197 unsigned short INFINITY[4] = {0x7fef,0xffff,0xffff,0xffff}; 198 #endif 199 #ifdef NANS 200 unsigned short NAN[4] = {0x7ff8,0x0000,0x0000,0x0000}; 201 #else 202 unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x0000}; 203 #endif 204 #ifdef MINUSZERO 205 unsigned short NEGZERO[4] = {0x8000,0x0000,0x0000,0x0000}; 206 #else 207 unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x0000}; 208 #endif 209 #endif 210 211 #ifdef DEC 212 /* 2**-56 = 1.38777878078144567553E-17 */ 213 unsigned short MACHEP[4] = {0022200,0000000,0000000,0000000}; 214 unsigned short UFLOWTHRESH[4] = {0x0080,0x0000,0x0000,0x0000}; 215 /* log 2**127 = 88.029691931113054295988 */ 216 unsigned short MAXLOG[4] = {041660,007463,0143742,025733,}; 217 /* log 2**-128 = -88.72283911167299960540 */ 218 unsigned short MINLOG[4] = {0141661,071027,0173721,0147572,}; 219 /* 2**127 = 1.701411834604692317316873e38 */ 220 unsigned short MAXNUM[4] = {077777,0177777,0177777,0177777,}; 221 unsigned short PI[4] = {040511,007732,0121041,064302,}; 222 unsigned short PIO2[4] = {040311,007732,0121041,064302,}; 223 unsigned short PIO4[4] = {040111,007732,0121041,064302,}; 224 unsigned short SQRT2[4] = {040265,002363,031771,0157145,}; 225 unsigned short SQRTH[4] = {040065,002363,031771,0157144,}; 226 unsigned short LOG2E[4] = {040270,0125073,024534,013761,}; 227 unsigned short SQ2OPI[4] = {040114,041051,0117241,0131204,}; 228 unsigned short LOGE2[4] = {040061,071027,0173721,0147572,}; 229 unsigned short LOGSQ2[4] = {037661,071027,0173721,0147572,}; 230 unsigned short THPIO4[4] = {040426,0145743,0174631,007222,}; 231 unsigned short TWOOPI[4] = {040042,0174603,067116,042025,}; 232 /* Approximate infinity by MAXNUM. */ 233 unsigned short INFINITY[4] = {077777,0177777,0177777,0177777,}; 234 unsigned short NAN[4] = {0000000,0000000,0000000,0000000}; 235 #ifdef MINUSZERO 236 unsigned short NEGZERO[4] = {0000000,0000000,0000000,0100000}; 237 #else 238 unsigned short NEGZERO[4] = {0000000,0000000,0000000,0000000}; 239 #endif 240 #endif 241 242 #ifndef UNK 243 extern unsigned short MACHEP[]; 244 extern unsigned short UFLOWTHRESH[]; 245 extern unsigned short MAXLOG[]; 246 extern unsigned short UNDLOG[]; 247 extern unsigned short MINLOG[]; 248 extern unsigned short MAXNUM[]; 249 extern unsigned short PI[]; 250 extern unsigned short PIO2[]; 251 extern unsigned short PIO4[]; 252 extern unsigned short SQRT2[]; 253 extern unsigned short SQRTH[]; 254 extern unsigned short LOG2E[]; 255 extern unsigned short SQ2OPI[]; 256 extern unsigned short LOGE2[]; 257 extern unsigned short LOGSQ2[]; 258 extern unsigned short THPIO4[]; 259 extern unsigned short TWOOPI[]; 260 extern unsigned short INFINITY[]; 261 extern unsigned short NAN[]; 262 extern unsigned short NEGZERO[]; 263 #endif 264