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