You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
7.0 KiB

  1. /**CHeaderFile*****************************************************************
  2. FileName [epd.h]
  3. PackageName [epd]
  4. Synopsis [The University of Colorado extended double precision package.]
  5. Description [arithmetic functions with extended double precision.]
  6. SeeAlso []
  7. Author [In-Ho Moon]
  8. Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
  9. All rights reserved.
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions
  12. are met:
  13. Redistributions of source code must retain the above copyright
  14. notice, this list of conditions and the following disclaimer.
  15. Redistributions in binary form must reproduce the above copyright
  16. notice, this list of conditions and the following disclaimer in the
  17. documentation and/or other materials provided with the distribution.
  18. Neither the name of the University of Colorado nor the names of its
  19. contributors may be used to endorse or promote products derived from
  20. this software without specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. POSSIBILITY OF SUCH DAMAGE.]
  33. Revision [$Id: epd.h,v 1.9 2004/08/13 18:20:30 fabio Exp $]
  34. ******************************************************************************/
  35. #ifndef _EPD
  36. #define _EPD
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*---------------------------------------------------------------------------*/
  41. /* Constant declarations */
  42. /*---------------------------------------------------------------------------*/
  43. #define EPD_MAX_BIN 1023
  44. #define EPD_MAX_DEC 308
  45. #define EPD_EXP_INF 0x7ff
  46. /*---------------------------------------------------------------------------*/
  47. /* Structure declarations */
  48. /*---------------------------------------------------------------------------*/
  49. /**Struct**********************************************************************
  50. Synopsis [IEEE double struct.]
  51. Description [IEEE double struct.]
  52. SeeAlso []
  53. ******************************************************************************/
  54. #ifdef EPD_BIG_ENDIAN
  55. struct IeeeDoubleStruct { /* BIG_ENDIAN */
  56. unsigned int sign: 1;
  57. unsigned int exponent: 11;
  58. unsigned int mantissa0: 20;
  59. unsigned int mantissa1: 32;
  60. };
  61. #else
  62. struct IeeeDoubleStruct { /* LITTLE_ENDIAN */
  63. unsigned int mantissa1: 32;
  64. unsigned int mantissa0: 20;
  65. unsigned int exponent: 11;
  66. unsigned int sign: 1;
  67. };
  68. #endif
  69. /**Struct**********************************************************************
  70. Synopsis [IEEE double NaN struct.]
  71. Description [IEEE double NaN struct.]
  72. SeeAlso []
  73. ******************************************************************************/
  74. #ifdef EPD_BIG_ENDIAN
  75. struct IeeeNanStruct { /* BIG_ENDIAN */
  76. unsigned int sign: 1;
  77. unsigned int exponent: 11;
  78. unsigned int quiet_bit: 1;
  79. unsigned int mantissa0: 19;
  80. unsigned int mantissa1: 32;
  81. };
  82. #else
  83. struct IeeeNanStruct { /* LITTLE_ENDIAN */
  84. unsigned int mantissa1: 32;
  85. unsigned int mantissa0: 19;
  86. unsigned int quiet_bit: 1;
  87. unsigned int exponent: 11;
  88. unsigned int sign: 1;
  89. };
  90. #endif
  91. /**Struct**********************************************************************
  92. Synopsis [Extended precision double to keep very large value.]
  93. Description [Extended precision double to keep very large value.]
  94. SeeAlso []
  95. ******************************************************************************/
  96. union EpTypeUnion {
  97. double value;
  98. struct IeeeDoubleStruct bits;
  99. struct IeeeNanStruct nan;
  100. };
  101. struct EpDoubleStruct {
  102. union EpTypeUnion type;
  103. int exponent;
  104. };
  105. /*---------------------------------------------------------------------------*/
  106. /* Type declarations */
  107. /*---------------------------------------------------------------------------*/
  108. typedef struct EpDoubleStruct EpDouble;
  109. typedef struct IeeeDoubleStruct IeeeDouble;
  110. typedef struct IeeeNanStruct IeeeNan;
  111. typedef union EpTypeUnion EpType;
  112. /**AutomaticStart*************************************************************/
  113. /*---------------------------------------------------------------------------*/
  114. /* Function prototypes */
  115. /*---------------------------------------------------------------------------*/
  116. extern EpDouble *EpdAlloc(void);
  117. extern int EpdCmp(const char *key1, const char *key2);
  118. extern void EpdFree(EpDouble *epd);
  119. extern void EpdGetString(EpDouble *epd, char *str);
  120. extern void EpdConvert(double value, EpDouble *epd);
  121. extern void EpdMultiply(EpDouble *epd1, double value);
  122. extern void EpdMultiply2(EpDouble *epd1, EpDouble *epd2);
  123. extern void EpdMultiply2Decimal(EpDouble *epd1, EpDouble *epd2);
  124. extern void EpdMultiply3(EpDouble *epd1, EpDouble *epd2, EpDouble *epd3);
  125. extern void EpdMultiply3Decimal(EpDouble *epd1, EpDouble *epd2, EpDouble *epd3);
  126. extern void EpdDivide(EpDouble *epd1, double value);
  127. extern void EpdDivide2(EpDouble *epd1, EpDouble *epd2);
  128. extern void EpdDivide3(EpDouble *epd1, EpDouble *epd2, EpDouble *epd3);
  129. extern void EpdAdd(EpDouble *epd1, double value);
  130. extern void EpdAdd2(EpDouble *epd1, EpDouble *epd2);
  131. extern void EpdAdd3(EpDouble *epd1, EpDouble *epd2, EpDouble *epd3);
  132. extern void EpdSubtract(EpDouble *epd1, double value);
  133. extern void EpdSubtract2(EpDouble *epd1, EpDouble *epd2);
  134. extern void EpdSubtract3(EpDouble *epd1, EpDouble *epd2, EpDouble *epd3);
  135. extern void EpdPow2(int n, EpDouble *epd);
  136. extern void EpdPow2Decimal(int n, EpDouble *epd);
  137. extern void EpdNormalize(EpDouble *epd);
  138. extern void EpdNormalizeDecimal(EpDouble *epd);
  139. extern void EpdGetValueAndDecimalExponent(EpDouble *epd, double *value, int *exponent);
  140. extern int EpdGetExponent(double value);
  141. extern int EpdGetExponentDecimal(double value);
  142. extern void EpdMakeInf(EpDouble *epd, int sign);
  143. extern void EpdMakeZero(EpDouble *epd, int sign);
  144. extern void EpdMakeNan(EpDouble *epd);
  145. extern void EpdCopy(EpDouble *from, EpDouble *to);
  146. extern int EpdIsInf(EpDouble *epd);
  147. extern int EpdIsZero(EpDouble *epd);
  148. extern int EpdIsNan(EpDouble *epd);
  149. extern int EpdIsNanOrInf(EpDouble *epd);
  150. extern int IsInfDouble(double value);
  151. extern int IsNanDouble(double value);
  152. extern int IsNanOrInfDouble(double value);
  153. /**AutomaticEnd***************************************************************/
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* _EPD */