1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #ifndef _VALUES_H 32*7c478bd9Sstevel@tonic-gate #define _VALUES_H 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.33 */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 39*7c478bd9Sstevel@tonic-gate extern "C" { 40*7c478bd9Sstevel@tonic-gate #endif 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * These values work with any binary representation of integers 44*7c478bd9Sstevel@tonic-gate * where the high-order bit contains the sign. 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* a number used normally for size of a shift */ 48*7c478bd9Sstevel@tonic-gate #define BITSPERBYTE 8 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #define BITS(type) (BITSPERBYTE * (long)sizeof (type)) 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* short, regular and long ints with only the high-order bit turned on */ 53*7c478bd9Sstevel@tonic-gate #define HIBITS ((short)(1 << (BITS(short) - 1))) 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate #define HIBITI (1U << (BITS(int) - 1)) 58*7c478bd9Sstevel@tonic-gate #define HIBITL (1UL << (BITS(long) - 1)) 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate #else 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate #define HIBITI ((unsigned)1 << (BITS(int) - 1)) 63*7c478bd9Sstevel@tonic-gate #define HIBITL (1L << (BITS(long) - 1)) 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate #endif 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate /* largest short, regular and long int */ 68*7c478bd9Sstevel@tonic-gate #define MAXSHORT ((short)~HIBITS) 69*7c478bd9Sstevel@tonic-gate #define MAXINT ((int)(~HIBITI)) 70*7c478bd9Sstevel@tonic-gate #define MAXLONG ((long)(~HIBITL)) 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate /* 73*7c478bd9Sstevel@tonic-gate * various values that describe the binary floating-point representation 74*7c478bd9Sstevel@tonic-gate * _EXPBASE - the exponent base 75*7c478bd9Sstevel@tonic-gate * DMAXEXP - the maximum exponent of a double (as returned by frexp()) 76*7c478bd9Sstevel@tonic-gate * FMAXEXP - the maximum exponent of a float (as returned by frexp()) 77*7c478bd9Sstevel@tonic-gate * DMINEXP - the minimum exponent of a double (as returned by frexp()) 78*7c478bd9Sstevel@tonic-gate * FMINEXP - the minimum exponent of a float (as returned by frexp()) 79*7c478bd9Sstevel@tonic-gate * MAXDOUBLE - the largest double 80*7c478bd9Sstevel@tonic-gate * ((_EXPBASE ** DMAXEXP) * (1 - (_EXPBASE ** -DSIGNIF))) 81*7c478bd9Sstevel@tonic-gate * MAXFLOAT - the largest float 82*7c478bd9Sstevel@tonic-gate * ((_EXPBASE ** FMAXEXP) * (1 - (_EXPBASE ** -FSIGNIF))) 83*7c478bd9Sstevel@tonic-gate * MINDOUBLE - the smallest double (_EXPBASE ** (DMINEXP - 1)) 84*7c478bd9Sstevel@tonic-gate * MINFLOAT - the smallest float (_EXPBASE ** (FMINEXP - 1)) 85*7c478bd9Sstevel@tonic-gate * DSIGNIF - the number of significant bits in a double 86*7c478bd9Sstevel@tonic-gate * FSIGNIF - the number of significant bits in a float 87*7c478bd9Sstevel@tonic-gate * DMAXPOWTWO - the largest power of two exactly representable as a double 88*7c478bd9Sstevel@tonic-gate * FMAXPOWTWO - the largest power of two exactly representable as a float 89*7c478bd9Sstevel@tonic-gate * _IEEE - 1 if IEEE standard representation is used 90*7c478bd9Sstevel@tonic-gate * _DEXPLEN - the number of bits for the exponent of a double 91*7c478bd9Sstevel@tonic-gate * _FEXPLEN - the number of bits for the exponent of a float 92*7c478bd9Sstevel@tonic-gate * _HIDDENBIT - 1 if high-significance bit of mantissa is implicit 93*7c478bd9Sstevel@tonic-gate * LN_MAXDOUBLE - the natural log of the largest double -- log(MAXDOUBLE) 94*7c478bd9Sstevel@tonic-gate * LN_MINDOUBLE - the natural log of the smallest double -- log(MINDOUBLE) 95*7c478bd9Sstevel@tonic-gate * LN_MAXFLOAT - the natural log of the largest float -- log(MAXFLOAT) 96*7c478bd9Sstevel@tonic-gate * LN_MINFLOAT - the natural log of the smallest float -- log(MINFLOAT) 97*7c478bd9Sstevel@tonic-gate */ 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * Currently, only IEEE-754 format is supported. 101*7c478bd9Sstevel@tonic-gate */ 102*7c478bd9Sstevel@tonic-gate #if defined(_IEEE_754) 103*7c478bd9Sstevel@tonic-gate #define MAXDOUBLE 1.79769313486231570e+308 104*7c478bd9Sstevel@tonic-gate #define MAXFLOAT ((float)3.40282346638528860e+38) 105*7c478bd9Sstevel@tonic-gate #define MINDOUBLE 4.94065645841246544e-324 106*7c478bd9Sstevel@tonic-gate #define MINFLOAT ((float)1.40129846432481707e-45) 107*7c478bd9Sstevel@tonic-gate #define _IEEE 1 108*7c478bd9Sstevel@tonic-gate #define _DEXPLEN 11 109*7c478bd9Sstevel@tonic-gate #define _HIDDENBIT 1 110*7c478bd9Sstevel@tonic-gate #define _LENBASE 1 111*7c478bd9Sstevel@tonic-gate #define DMINEXP (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3)) 112*7c478bd9Sstevel@tonic-gate #define FMINEXP (-(FMAXEXP + FSIGNIF - _HIDDENBIT - 3)) 113*7c478bd9Sstevel@tonic-gate #else 114*7c478bd9Sstevel@tonic-gate /* #error is strictly ansi-C, but works as well as anything for K&R systems. */ 115*7c478bd9Sstevel@tonic-gate #error "ISA not supported" 116*7c478bd9Sstevel@tonic-gate #endif 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate #define _EXPBASE (1 << _LENBASE) 119*7c478bd9Sstevel@tonic-gate #define _FEXPLEN 8 120*7c478bd9Sstevel@tonic-gate #define DSIGNIF (BITS(double) - _DEXPLEN + _HIDDENBIT - 1) 121*7c478bd9Sstevel@tonic-gate #define FSIGNIF (BITS(float) - _FEXPLEN + _HIDDENBIT - 1) 122*7c478bd9Sstevel@tonic-gate #define DMAXPOWTWO ((double)(1 << (BITS(int) - 2)) * \ 123*7c478bd9Sstevel@tonic-gate (1 << (DSIGNIF - BITS(int) + 1))) 124*7c478bd9Sstevel@tonic-gate #define FMAXPOWTWO ((float)(1 << (FSIGNIF - 1))) 125*7c478bd9Sstevel@tonic-gate #define DMAXEXP ((1 << (_DEXPLEN - 1)) - 1 + _IEEE) 126*7c478bd9Sstevel@tonic-gate #define FMAXEXP ((1 << (_FEXPLEN - 1)) - 1 + _IEEE) 127*7c478bd9Sstevel@tonic-gate #define LN_MAXDOUBLE (M_LN2 * DMAXEXP) 128*7c478bd9Sstevel@tonic-gate #define LN_MAXFLOAT (float)(M_LN2 * FMAXEXP) 129*7c478bd9Sstevel@tonic-gate #define LN_MINDOUBLE (M_LN2 * (DMINEXP - 1)) 130*7c478bd9Sstevel@tonic-gate #define LN_MINFLOAT (float)(M_LN2 * (FMINEXP - 1)) 131*7c478bd9Sstevel@tonic-gate #define H_PREC (DSIGNIF % 2 ? (1 << DSIGNIF/2) * M_SQRT2 : 1 << DSIGNIF/2) 132*7c478bd9Sstevel@tonic-gate #define FH_PREC \ 133*7c478bd9Sstevel@tonic-gate (float)(FSIGNIF % 2 ? (1 << FSIGNIF/2) * M_SQRT2 : 1 << FSIGNIF/2) 134*7c478bd9Sstevel@tonic-gate #define X_EPS (1.0/H_PREC) 135*7c478bd9Sstevel@tonic-gate #define FX_EPS (float)((float)1.0/FH_PREC) 136*7c478bd9Sstevel@tonic-gate #define X_PLOSS ((double)(int)(M_PI * H_PREC)) 137*7c478bd9Sstevel@tonic-gate #define FX_PLOSS ((float)(int)(M_PI * FH_PREC)) 138*7c478bd9Sstevel@tonic-gate #define X_TLOSS (M_PI * DMAXPOWTWO) 139*7c478bd9Sstevel@tonic-gate #define FX_TLOSS (float)(M_PI * FMAXPOWTWO) 140*7c478bd9Sstevel@tonic-gate #define M_LN2 0.69314718055994530942 141*7c478bd9Sstevel@tonic-gate #define M_PI 3.14159265358979323846 142*7c478bd9Sstevel@tonic-gate #define M_SQRT2 1.41421356237309504880 143*7c478bd9Sstevel@tonic-gate #define MAXBEXP DMAXEXP /* for backward compatibility */ 144*7c478bd9Sstevel@tonic-gate #define MINBEXP DMINEXP /* for backward compatibility */ 145*7c478bd9Sstevel@tonic-gate #define MAXPOWTWO DMAXPOWTWO /* for backward compatibility */ 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate #endif 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate #endif /* _VALUES_H */ 152