home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / gmt_os2.zip / src / values.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-20  |  6.0 KB  |  168 lines

  1. /*    Copyright (c) 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8. #ifndef    _VALUES_H
  9. #define    _VALUES_H
  10.  
  11. #pragma ident    "@(#)values.h    1.11    93/11/01 SMI"    /* SVr4.0 1.33    */
  12.  
  13. #ifdef    __cplusplus
  14. extern "C" {
  15. #endif
  16.  
  17. /*
  18.  * These values work with any binary representation of integers
  19.  * where the high-order bit contains the sign.
  20.  */
  21.  
  22. /* a number used normally for size of a shift */
  23. #define    BITSPERBYTE    8
  24.  
  25. #define    BITS(type)    (BITSPERBYTE * (int)sizeof (type))
  26.  
  27. /* short, regular and long ints with only the high-order bit turned on */
  28. #define    HIBITS    ((short)(1 << BITS(short) - 1))
  29.  
  30. #if defined(__STDC__)
  31.  
  32. #define    HIBITI    (1U << BITS(int) - 1)
  33. #define    HIBITL    (1UL << BITS(long) - 1)
  34.  
  35. #else
  36.  
  37. #define    HIBITI    ((unsigned)1 << BITS(int) - 1)
  38. #define    HIBITL    (1L << BITS(long) - 1)
  39.  
  40. #endif
  41.  
  42. /* largest short, regular and long int */
  43. #define    MAXSHORT    ((short)~HIBITS)
  44. #define    MAXINT    ((int)(~HIBITI))
  45. #define    MAXLONG    ((long)(~HIBITL))
  46.  
  47. /*
  48.  * various values that describe the binary floating-point representation
  49.  * _EXPBASE    - the exponent base
  50.  * DMAXEXP    - the maximum exponent of a double (as returned by frexp())
  51.  * FMAXEXP    - the maximum exponent of a float  (as returned by frexp())
  52.  * DMINEXP    - the minimum exponent of a double (as returned by frexp())
  53.  * FMINEXP    - the minimum exponent of a float  (as returned by frexp())
  54.  * MAXDOUBLE    - the largest double
  55.  *            ((_EXPBASE ** DMAXEXP) * (1 - (_EXPBASE ** -DSIGNIF)))
  56.  * MAXFLOAT    - the largest float
  57.  *            ((_EXPBASE ** FMAXEXP) * (1 - (_EXPBASE ** -FSIGNIF)))
  58.  * MINDOUBLE    - the smallest double (_EXPBASE ** (DMINEXP - 1))
  59.  * MINFLOAT    - the smallest float (_EXPBASE ** (FMINEXP - 1))
  60.  * DSIGNIF    - the number of significant bits in a double
  61.  * FSIGNIF    - the number of significant bits in a float
  62.  * DMAXPOWTWO    - the largest power of two exactly representable as a double
  63.  * FMAXPOWTWO    - the largest power of two exactly representable as a float
  64.  * _IEEE    - 1 if IEEE standard representation is used
  65.  * _DEXPLEN    - the number of bits for the exponent of a double
  66.  * _FEXPLEN    - the number of bits for the exponent of a float
  67.  * _HIDDENBIT    - 1 if high-significance bit of mantissa is implicit
  68.  * LN_MAXDOUBLE    - the natural log of the largest double  -- log(MAXDOUBLE)
  69.  * LN_MINDOUBLE    - the natural log of the smallest double -- log(MINDOUBLE)
  70.  * LN_MAXFLOAT    - the natural log of the largest float  -- log(MAXFLOAT)
  71.  * LN_MINFLOAT    - the natural log of the smallest float -- log(MINFLOAT)
  72.  */
  73.  
  74. #if defined(__STDC__)
  75.  
  76. /*
  77.  * Note that the following construct, "!#machine(name)", is a non-standard
  78.  * extension to ANSI-C.  It is maintained here to provide compatibility
  79.  * for existing compilations systems, but should be viewed as transitional
  80.  * and may be removed in a future release.  If it is required that this
  81.  * file not contain this extension, edit this file to remove the offending
  82.  * condition.
  83.  *
  84.  * These machines are all IEEE-754:
  85.  */
  86. #if #machine(i386) || defined(__i386) || #machine(sparc) || defined(__sparc)
  87. #define    MAXDOUBLE    1.79769313486231570e+308
  88. #define    MAXFLOAT    ((float)3.40282346638528860e+38)
  89. #define    MINDOUBLE    4.94065645841246544e-324
  90. #define    MINFLOAT    ((float)1.40129846432481707e-45)
  91. #define    _IEEE        1
  92. #define    _DEXPLEN    11
  93. #define    _HIDDENBIT    1
  94. #define    _LENBASE    1
  95. #define    DMINEXP    (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3))
  96. #define    FMINEXP    (-(FMAXEXP + FSIGNIF - _HIDDENBIT - 3))
  97. #else
  98. #error ISA not supported
  99. #endif
  100.  
  101. #else
  102.  
  103. /*
  104.  * These machines are all IEEE-754:
  105.  */
  106. #if defined(i386) || defined(__i386) || defined(sparc) || defined(__sparc)
  107. #define    MAXDOUBLE    1.79769313486231570e+308
  108. #define    MAXFLOAT    ((float)3.40282346638528860e+38)
  109. #define    MINDOUBLE    4.94065645841246544e-324
  110. #define    MINFLOAT    ((float)1.40129846432481707e-45)
  111. #define    _IEEE        1
  112. #define    _DEXPLEN    11
  113. #define    _HIDDENBIT    1
  114. #define    _LENBASE    1
  115. #define    DMINEXP    (-(DMAXEXP + DSIGNIF - _HIDDENBIT - 3))
  116. #define    FMINEXP    (-(FMAXEXP + FSIGNIF - _HIDDENBIT - 3))
  117. #else
  118. /* #error is strictly ansi-C, but works as well as anything for K&R systems. */
  119. #error ISA not supported
  120. #endif
  121.  
  122. #endif    /* __STDC__ */
  123.  
  124. #define    _EXPBASE    (1 << _LENBASE)
  125. #define    _FEXPLEN    8
  126. #define    DSIGNIF    (BITS(double) - _DEXPLEN + _HIDDENBIT - 1)
  127. #define    FSIGNIF    (BITS(float)  - _FEXPLEN + _HIDDENBIT - 1)
  128. #define    DMAXPOWTWO    ((double)(1L << BITS(long) - 2) * \
  129.                 (1L << DSIGNIF - BITS(long) + 1))
  130. #define    FMAXPOWTWO    ((float)(1L << FSIGNIF - 1))
  131. #define    DMAXEXP    ((1 << _DEXPLEN - 1) - 1 + _IEEE)
  132. #define    FMAXEXP    ((1 << _FEXPLEN - 1) - 1 + _IEEE)
  133. #define    LN_MAXDOUBLE    (M_LN2 * DMAXEXP)
  134. #define    LN_MAXFLOAT    (float)(M_LN2 * FMAXEXP)
  135. #define    LN_MINDOUBLE    (M_LN2 * (DMINEXP - 1))
  136. #define    LN_MINFLOAT    (float)(M_LN2 * (FMINEXP - 1))
  137. #define    H_PREC    (DSIGNIF % 2 ? (1L << DSIGNIF/2) * M_SQRT2 : 1L << DSIGNIF/2)
  138. #define    FH_PREC \
  139.     (float)(FSIGNIF % 2 ? (1L << FSIGNIF/2) * M_SQRT2 : 1L << FSIGNIF/2)
  140. #define    X_EPS    (1.0/H_PREC)
  141. #define    FX_EPS    (float)((float)1.0/FH_PREC)
  142. #define    X_PLOSS    ((double)(long)(M_PI * H_PREC))
  143. #define    FX_PLOSS ((float)(long)(M_PI * FH_PREC))
  144. #define    X_TLOSS    (M_PI * DMAXPOWTWO)
  145. #define    FX_TLOSS (float)(M_PI * FMAXPOWTWO)
  146. #define    M_LN2        0.69314718055994530942
  147. #define    M_PI        3.14159265358979323846
  148. #define    M_SQRT2        1.41421356237309504880
  149.  
  150. /*********************************************************************/
  151.  
  152. /*    Definitions of M_PI_2, M_PI_4, & M_E were added by A. Cogbill  */
  153. /*    These constants typically defined in the <math.h> header       */
  154.  
  155. #define   M_PI_2    (0.50 * M_PI)
  156. #define   M_PI_4    (0.25 * M_PI)
  157. #define   M_E       2.71828182845904523536
  158.  
  159. /********************************************************************/
  160. #define    MAXBEXP    DMAXEXP /* for backward compatibility */
  161. #define    MINBEXP    DMINEXP /* for backward compatibility */
  162. #define    MAXPOWTWO    DMAXPOWTWO /* for backward compatibility */
  163.  
  164. #ifdef    __cplusplus
  165. }
  166. #endif
  167.  
  168. #endif    /* _VALUES_H */