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 77double MACHEP = 1.11022302462515654042E-16; /* 2**-53 */ 78#else 79double MACHEP = 1.38777878078144567553E-17; /* 2**-56 */ 80#endif 81double UFLOWTHRESH = 2.22507385850720138309E-308; /* 2**-1022 */ 82#ifdef DENORMAL 83double MAXLOG = 7.09782712893383996732E2; /* log(MAXNUM) */ 84/* double MINLOG = -7.44440071921381262314E2; */ /* log(2**-1074) */ 85double MINLOG = -7.451332191019412076235E2; /* log(2**-1075) */ 86#else 87double MAXLOG = 7.08396418532264106224E2; /* log 2**1022 */ 88double MINLOG = -7.08396418532264106224E2; /* log 2**-1022 */ 89#endif 90double MAXNUM = 1.79769313486231570815E308; /* 2**1024*(1-MACHEP) */ 91double PI = 3.14159265358979323846; /* pi */ 92double PIO2 = 1.57079632679489661923; /* pi/2 */ 93double PIO4 = 7.85398163397448309616E-1; /* pi/4 */ 94double SQRT2 = 1.41421356237309504880; /* sqrt(2) */ 95double SQRTH = 7.07106781186547524401E-1; /* sqrt(2)/2 */ 96double LOG2E = 1.4426950408889634073599; /* 1/log(2) */ 97double SQ2OPI = 7.9788456080286535587989E-1; /* sqrt( 2/pi ) */ 98double LOGE2 = 6.93147180559945309417E-1; /* log(2) */ 99double LOGSQ2 = 3.46573590279972654709E-1; /* log(2)/2 */ 100double THPIO4 = 2.35619449019234492885; /* 3*pi/4 */ 101double TWOOPI = 6.36619772367581343075535E-1; /* 2/pi */ 102#ifdef INFINITIES 103double INFINITY = 1.0/0.0; /* 99e999; */ 104#else 105double INFINITY = 1.79769313486231570815E308; /* 2**1024*(1-MACHEP) */ 106#endif 107#ifdef NANS 108double NAN = 1.0/0.0 - 1.0/0.0; 109#else 110double NAN = 0.0; 111#endif 112#ifdef MINUSZERO 113double NEGZERO = -0.0; 114#else 115double NEGZERO = 0.0; 116#endif 117#endif 118 119#ifdef IBMPC 120 /* 2**-53 = 1.11022302462515654042E-16 */ 121unsigned short MACHEP[4] = {0x0000,0x0000,0x0000,0x3ca0}; 122unsigned short UFLOWTHRESH[4] = {0x0000,0x0000,0x0000,0x0010}; 123#ifdef DENORMAL 124 /* log(MAXNUM) = 7.09782712893383996732224E2 */ 125unsigned short MAXLOG[4] = {0x39ef,0xfefa,0x2e42,0x4086}; 126 /* log(2**-1074) = - -7.44440071921381262314E2 */ 127/*unsigned short MINLOG[4] = {0x71c3,0x446d,0x4385,0xc087};*/ 128unsigned short MINLOG[4] = {0x3052,0xd52d,0x4910,0xc087}; 129#else 130 /* log(2**1022) = 7.08396418532264106224E2 */ 131unsigned short MAXLOG[4] = {0xbcd2,0xdd7a,0x232b,0x4086}; 132 /* log(2**-1022) = - 7.08396418532264106224E2 */ 133unsigned short MINLOG[4] = {0xbcd2,0xdd7a,0x232b,0xc086}; 134#endif 135 /* 2**1024*(1-MACHEP) = 1.7976931348623158E308 */ 136unsigned short MAXNUM[4] = {0xffff,0xffff,0xffff,0x7fef}; 137unsigned short PI[4] = {0x2d18,0x5444,0x21fb,0x4009}; 138unsigned short PIO2[4] = {0x2d18,0x5444,0x21fb,0x3ff9}; 139unsigned short PIO4[4] = {0x2d18,0x5444,0x21fb,0x3fe9}; 140unsigned short SQRT2[4] = {0x3bcd,0x667f,0xa09e,0x3ff6}; 141unsigned short SQRTH[4] = {0x3bcd,0x667f,0xa09e,0x3fe6}; 142unsigned short LOG2E[4] = {0x82fe,0x652b,0x1547,0x3ff7}; 143unsigned short SQ2OPI[4] = {0x3651,0x33d4,0x8845,0x3fe9}; 144unsigned short LOGE2[4] = {0x39ef,0xfefa,0x2e42,0x3fe6}; 145unsigned short LOGSQ2[4] = {0x39ef,0xfefa,0x2e42,0x3fd6}; 146unsigned short THPIO4[4] = {0x21d2,0x7f33,0xd97c,0x4002}; 147unsigned short TWOOPI[4] = {0xc883,0x6dc9,0x5f30,0x3fe4}; 148#ifdef INFINITIES 149unsigned short INFINITY[4] = {0x0000,0x0000,0x0000,0x7ff0}; 150#else 151unsigned short INFINITY[4] = {0xffff,0xffff,0xffff,0x7fef}; 152#endif 153#ifdef NANS 154unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x7ffc}; 155#else 156unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x0000}; 157#endif 158#ifdef MINUSZERO 159unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x8000}; 160#else 161unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x0000}; 162#endif 163#endif 164 165#ifdef MIEEE 166 /* 2**-53 = 1.11022302462515654042E-16 */ 167unsigned short MACHEP[4] = {0x3ca0,0x0000,0x0000,0x0000}; 168unsigned short UFLOWTHRESH[4] = {0x0010,0x0000,0x0000,0x0000}; 169#ifdef DENORMAL 170 /* log(2**1024) = 7.09782712893383996843E2 */ 171unsigned short MAXLOG[4] = {0x4086,0x2e42,0xfefa,0x39ef}; 172 /* log(2**-1074) = - -7.44440071921381262314E2 */ 173/* unsigned short MINLOG[4] = {0xc087,0x4385,0x446d,0x71c3}; */ 174unsigned short MINLOG[4] = {0xc087,0x4910,0xd52d,0x3052}; 175#else 176 /* log(2**1022) = 7.08396418532264106224E2 */ 177unsigned short MAXLOG[4] = {0x4086,0x232b,0xdd7a,0xbcd2}; 178 /* log(2**-1022) = - 7.08396418532264106224E2 */ 179unsigned short MINLOG[4] = {0xc086,0x232b,0xdd7a,0xbcd2}; 180#endif 181 /* 2**1024*(1-MACHEP) = 1.7976931348623158E308 */ 182unsigned short MAXNUM[4] = {0x7fef,0xffff,0xffff,0xffff}; 183unsigned short PI[4] = {0x4009,0x21fb,0x5444,0x2d18}; 184unsigned short PIO2[4] = {0x3ff9,0x21fb,0x5444,0x2d18}; 185unsigned short PIO4[4] = {0x3fe9,0x21fb,0x5444,0x2d18}; 186unsigned short SQRT2[4] = {0x3ff6,0xa09e,0x667f,0x3bcd}; 187unsigned short SQRTH[4] = {0x3fe6,0xa09e,0x667f,0x3bcd}; 188unsigned short LOG2E[4] = {0x3ff7,0x1547,0x652b,0x82fe}; 189unsigned short SQ2OPI[4] = {0x3fe9,0x8845,0x33d4,0x3651}; 190unsigned short LOGE2[4] = {0x3fe6,0x2e42,0xfefa,0x39ef}; 191unsigned short LOGSQ2[4] = {0x3fd6,0x2e42,0xfefa,0x39ef}; 192unsigned short THPIO4[4] = {0x4002,0xd97c,0x7f33,0x21d2}; 193unsigned short TWOOPI[4] = {0x3fe4,0x5f30,0x6dc9,0xc883}; 194#ifdef INFINITIES 195unsigned short INFINITY[4] = {0x7ff0,0x0000,0x0000,0x0000}; 196#else 197unsigned short INFINITY[4] = {0x7fef,0xffff,0xffff,0xffff}; 198#endif 199#ifdef NANS 200unsigned short NAN[4] = {0x7ff8,0x0000,0x0000,0x0000}; 201#else 202unsigned short NAN[4] = {0x0000,0x0000,0x0000,0x0000}; 203#endif 204#ifdef MINUSZERO 205unsigned short NEGZERO[4] = {0x8000,0x0000,0x0000,0x0000}; 206#else 207unsigned short NEGZERO[4] = {0x0000,0x0000,0x0000,0x0000}; 208#endif 209#endif 210 211#ifdef DEC 212 /* 2**-56 = 1.38777878078144567553E-17 */ 213unsigned short MACHEP[4] = {0022200,0000000,0000000,0000000}; 214unsigned short UFLOWTHRESH[4] = {0x0080,0x0000,0x0000,0x0000}; 215 /* log 2**127 = 88.029691931113054295988 */ 216unsigned short MAXLOG[4] = {041660,007463,0143742,025733,}; 217 /* log 2**-128 = -88.72283911167299960540 */ 218unsigned short MINLOG[4] = {0141661,071027,0173721,0147572,}; 219 /* 2**127 = 1.701411834604692317316873e38 */ 220unsigned short MAXNUM[4] = {077777,0177777,0177777,0177777,}; 221unsigned short PI[4] = {040511,007732,0121041,064302,}; 222unsigned short PIO2[4] = {040311,007732,0121041,064302,}; 223unsigned short PIO4[4] = {040111,007732,0121041,064302,}; 224unsigned short SQRT2[4] = {040265,002363,031771,0157145,}; 225unsigned short SQRTH[4] = {040065,002363,031771,0157144,}; 226unsigned short LOG2E[4] = {040270,0125073,024534,013761,}; 227unsigned short SQ2OPI[4] = {040114,041051,0117241,0131204,}; 228unsigned short LOGE2[4] = {040061,071027,0173721,0147572,}; 229unsigned short LOGSQ2[4] = {037661,071027,0173721,0147572,}; 230unsigned short THPIO4[4] = {040426,0145743,0174631,007222,}; 231unsigned short TWOOPI[4] = {040042,0174603,067116,042025,}; 232/* Approximate infinity by MAXNUM. */ 233unsigned short INFINITY[4] = {077777,0177777,0177777,0177777,}; 234unsigned short NAN[4] = {0000000,0000000,0000000,0000000}; 235#ifdef MINUSZERO 236unsigned short NEGZERO[4] = {0000000,0000000,0000000,0100000}; 237#else 238unsigned short NEGZERO[4] = {0000000,0000000,0000000,0000000}; 239#endif 240#endif 241 242#ifndef UNK 243extern unsigned short MACHEP[]; 244extern unsigned short UFLOWTHRESH[]; 245extern unsigned short MAXLOG[]; 246extern unsigned short UNDLOG[]; 247extern unsigned short MINLOG[]; 248extern unsigned short MAXNUM[]; 249extern unsigned short PI[]; 250extern unsigned short PIO2[]; 251extern unsigned short PIO4[]; 252extern unsigned short SQRT2[]; 253extern unsigned short SQRTH[]; 254extern unsigned short LOG2E[]; 255extern unsigned short SQ2OPI[]; 256extern unsigned short LOGE2[]; 257extern unsigned short LOGSQ2[]; 258extern unsigned short THPIO4[]; 259extern unsigned short TWOOPI[]; 260extern unsigned short INFINITY[]; 261extern unsigned short NAN[]; 262extern unsigned short NEGZERO[]; 263#endif 264