1*36cd4f11Sbluhm /* $OpenBSD: mconf.h,v 1.3 2017/07/27 15:08:37 bluhm Exp $ */ 2b7275c88Smartynas 3b7275c88Smartynas /* 4b7275c88Smartynas * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 5b7275c88Smartynas * 6b7275c88Smartynas * Permission to use, copy, modify, and distribute this software for any 7b7275c88Smartynas * purpose with or without fee is hereby granted, provided that the above 8b7275c88Smartynas * copyright notice and this permission notice appear in all copies. 9b7275c88Smartynas * 10b7275c88Smartynas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11b7275c88Smartynas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12b7275c88Smartynas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13b7275c88Smartynas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14b7275c88Smartynas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15b7275c88Smartynas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16b7275c88Smartynas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17b7275c88Smartynas */ 18b7275c88Smartynas 19b7275c88Smartynas /* mconf.h 20b7275c88Smartynas * 21b7275c88Smartynas * Common include file for math routines 22b7275c88Smartynas * 23b7275c88Smartynas * 24b7275c88Smartynas * 25b7275c88Smartynas * SYNOPSIS: 26b7275c88Smartynas * 27b7275c88Smartynas * #include "mconf.h" 28b7275c88Smartynas * 29b7275c88Smartynas * 30b7275c88Smartynas * 31b7275c88Smartynas * DESCRIPTION: 32b7275c88Smartynas * 33b7275c88Smartynas * This file contains definitions for error codes that are 34b7275c88Smartynas * passed to the common error handling routine mtherr() 35b7275c88Smartynas * (which see). 36b7275c88Smartynas * 37b7275c88Smartynas * The file also includes a conditional assembly definition 38b7275c88Smartynas * for the type of computer arithmetic (IEEE, DEC, Motorola 39b7275c88Smartynas * IEEE, or UNKnown). 40b7275c88Smartynas * 41b7275c88Smartynas * For Digital Equipment PDP-11 and VAX computers, certain 42b7275c88Smartynas * IBM systems, and others that use numbers with a 56-bit 43b7275c88Smartynas * significand, the symbol DEC should be defined. In this 44b7275c88Smartynas * mode, most floating point constants are given as arrays 45b7275c88Smartynas * of octal integers to eliminate decimal to binary conversion 46b7275c88Smartynas * errors that might be introduced by the compiler. 47b7275c88Smartynas * 48b7275c88Smartynas * For little-endian computers, such as IBM PC, that follow the 49b7275c88Smartynas * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE 50b7275c88Smartynas * Std 754-1985), the symbol IBMPC should be defined. These 51b7275c88Smartynas * numbers have 53-bit significands. In this mode, constants 52b7275c88Smartynas * are provided as arrays of hexadecimal 16 bit integers. 53b7275c88Smartynas * 54b7275c88Smartynas * Big-endian IEEE format is denoted MIEEE. On some RISC 55b7275c88Smartynas * systems such as Sun SPARC, double precision constants 56b7275c88Smartynas * must be stored on 8-byte address boundaries. Since integer 57b7275c88Smartynas * arrays may be aligned differently, the MIEEE configuration 58b7275c88Smartynas * may fail on such machines. 59b7275c88Smartynas * 60b7275c88Smartynas * To accommodate other types of computer arithmetic, all 61b7275c88Smartynas * constants are also provided in a normal decimal radix 62b7275c88Smartynas * which one can hope are correctly converted to a suitable 63b7275c88Smartynas * format by the available C language compiler. To invoke 64b7275c88Smartynas * this mode, define the symbol UNK. 65b7275c88Smartynas * 66b7275c88Smartynas * An important difference among these modes is a predefined 67b7275c88Smartynas * set of machine arithmetic constants for each. The numbers 68b7275c88Smartynas * MACHEP (the machine roundoff error), MAXNUM (largest number 69b7275c88Smartynas * represented), and several other parameters are preset by 70b7275c88Smartynas * the configuration symbol. Check the file const.c to 71b7275c88Smartynas * ensure that these values are correct for your computer. 72b7275c88Smartynas * 73b7275c88Smartynas * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL 74b7275c88Smartynas * may fail on many systems. Verify that they are supposed 75b7275c88Smartynas * to work on your computer. 76b7275c88Smartynas */ 77b7275c88Smartynas 78b7275c88Smartynas #include <sys/types.h> 79be9b7050Sguenther #include <endian.h> 80b7275c88Smartynas 81b7275c88Smartynas /* Constant definitions for math error conditions 82b7275c88Smartynas */ 83b7275c88Smartynas 84b7275c88Smartynas #define DOMAIN 1 /* argument domain error */ 85b7275c88Smartynas #define SING 2 /* argument singularity */ 86b7275c88Smartynas #define OVERFLOW 3 /* overflow range error */ 87b7275c88Smartynas #define UNDERFLOW 4 /* underflow range error */ 88b7275c88Smartynas #define TLOSS 5 /* total loss of precision */ 89b7275c88Smartynas #define PLOSS 6 /* partial loss of precision */ 90b7275c88Smartynas 91b7275c88Smartynas #define EDOM 33 92b7275c88Smartynas #define ERANGE 34 93b7275c88Smartynas 94b7275c88Smartynas /* Complex numeral. */ 95b7275c88Smartynas typedef struct 96b7275c88Smartynas { 97b7275c88Smartynas double r; 98b7275c88Smartynas double i; 99b7275c88Smartynas } cmplx; 100b7275c88Smartynas 101b7275c88Smartynas /* Long double complex numeral. */ 102b7275c88Smartynas typedef struct 103b7275c88Smartynas { 104b7275c88Smartynas double r; 105b7275c88Smartynas double i; 106b7275c88Smartynas } cmplxl; 107b7275c88Smartynas 108b7275c88Smartynas /* Type of computer arithmetic */ 109b7275c88Smartynas 110b7275c88Smartynas /* PDP-11, Pro350, VAX: 111b7275c88Smartynas */ 112b7275c88Smartynas #ifdef __vax__ 113b7275c88Smartynas #define DEC 1 114b7275c88Smartynas #endif /* __vax__ */ 115b7275c88Smartynas 116b7275c88Smartynas /* Intel IEEE, low order words come first: 117b7275c88Smartynas */ 118b7275c88Smartynas /* #define IBMPC 1 */ 119b7275c88Smartynas 120b7275c88Smartynas /* Motorola IEEE, high order words come first 121b7275c88Smartynas * (Sun 680x0 workstation): 122b7275c88Smartynas */ 123b7275c88Smartynas /* #define MIEEE 1 */ 124b7275c88Smartynas 125b7275c88Smartynas /* UNKnown arithmetic, invokes coefficients given in 126b7275c88Smartynas * normal decimal format. Beware of range boundary 127b7275c88Smartynas * problems (MACHEP, MAXLOG, etc. in const.c) and 128b7275c88Smartynas * roundoff problems in pow.c: 129b7275c88Smartynas * (Sun SPARCstation) 130b7275c88Smartynas */ 131b7275c88Smartynas #ifndef __vax__ 132b7275c88Smartynas #define UNK 1 133b7275c88Smartynas #endif /* !__vax__ */ 134b7275c88Smartynas 135b7275c88Smartynas /* If you define UNK, then be sure to set BIGENDIAN properly. */ 136b7275c88Smartynas #if BYTE_ORDER == BIG_ENDIAN 137b7275c88Smartynas #define BIGENDIAN 1 138b7275c88Smartynas #endif /* BYTE_ORDER == BIG_ENDIAN */ 139b7275c88Smartynas 140b7275c88Smartynas /* Define this `volatile' if your compiler thinks 141b7275c88Smartynas * that floating point arithmetic obeys the associative 142b7275c88Smartynas * and distributive laws. It will defeat some optimizations 143b7275c88Smartynas * (but probably not enough of them). 144b7275c88Smartynas * 145b7275c88Smartynas * #define VOLATILE volatile 146b7275c88Smartynas */ 147b7275c88Smartynas #define VOLATILE 148b7275c88Smartynas 149b7275c88Smartynas /* For 12-byte long doubles on an i386, pad a 16-bit short 0 150b7275c88Smartynas * to the end of real constants initialized by integer arrays. 151b7275c88Smartynas * 152b7275c88Smartynas * #define XPD 0, 153b7275c88Smartynas * 154b7275c88Smartynas * Otherwise, the type is 10 bytes long and XPD should be 155b7275c88Smartynas * defined blank (e.g., Microsoft C). 156b7275c88Smartynas * 157b7275c88Smartynas * #define XPD 158b7275c88Smartynas */ 159b7275c88Smartynas #define XPD 0, 160b7275c88Smartynas 161b7275c88Smartynas /* Define to support tiny denormal numbers, else undefine. */ 162b7275c88Smartynas #ifndef __vax__ 163b7275c88Smartynas #define DENORMAL 1 164b7275c88Smartynas #endif /* !__vax__ */ 165b7275c88Smartynas 166b7275c88Smartynas /* Define to ask for infinity support, else undefine. */ 167b7275c88Smartynas #ifndef __vax__ 168b7275c88Smartynas #define INFINITIES 1 169b7275c88Smartynas #endif /* !__vax__ */ 170b7275c88Smartynas 171b7275c88Smartynas /* Define to ask for support of numbers that are Not-a-Number, 172b7275c88Smartynas else undefine. This may automatically define INFINITIES in some files. */ 173b7275c88Smartynas #ifndef __vax__ 174b7275c88Smartynas #define NANS 1 175b7275c88Smartynas #endif /* !__vax__ */ 176b7275c88Smartynas 177b7275c88Smartynas /* Define to distinguish between -0.0 and +0.0. */ 178b7275c88Smartynas #define MINUSZERO 1 179b7275c88Smartynas 180b7275c88Smartynas /* Define 1 for ANSI C atan2() function 181b7275c88Smartynas See atan.c and clog.c. */ 182b7275c88Smartynas #define ANSIC 1 183b7275c88Smartynas 184b7275c88Smartynas int mtherr(); 185b7275c88Smartynas 186b7275c88Smartynas /* Variable for error reporting. See mtherr.c. */ 187b7275c88Smartynas extern int merror; 188*36cd4f11Sbluhm 189*36cd4f11Sbluhm int drand(double *); 190