decDouble.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* decDouble module header for the decNumber C Library.
  2. Copyright (C) 2007-2013 Free Software Foundation, Inc.
  3. Contributed by IBM Corporation. Author Mike Cowlishaw.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. /* ------------------------------------------------------------------ */
  21. /* decDouble.h -- Decimal 64-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. #if !defined(DECDOUBLE)
  24. #define DECDOUBLE
  25. #define DECDOUBLENAME "decimalDouble" /* Short name */
  26. #define DECDOUBLETITLE "Decimal 64-bit datum" /* Verbose name */
  27. #define DECDOUBLEAUTHOR "Mike Cowlishaw" /* Who to blame */
  28. /* parameters for decDoubles */
  29. #define DECDOUBLE_Bytes 8 /* length */
  30. #define DECDOUBLE_Pmax 16 /* maximum precision (digits) */
  31. #define DECDOUBLE_Emin -383 /* minimum adjusted exponent */
  32. #define DECDOUBLE_Emax 384 /* maximum adjusted exponent */
  33. #define DECDOUBLE_EmaxD 3 /* maximum exponent digits */
  34. #define DECDOUBLE_Bias 398 /* bias for the exponent */
  35. #define DECDOUBLE_String 25 /* maximum string length, +1 */
  36. #define DECDOUBLE_EconL 8 /* exponent continuation length */
  37. #define DECDOUBLE_Declets 5 /* count of declets */
  38. /* highest biased exponent (Elimit-1) */
  39. #define DECDOUBLE_Ehigh (DECDOUBLE_Emax + DECDOUBLE_Bias - (DECDOUBLE_Pmax-1))
  40. /* Required includes */
  41. #include "decContext.h"
  42. #include "decQuad.h"
  43. /* The decDouble decimal 64-bit type, accessible by all sizes */
  44. typedef union {
  45. uint8_t bytes[DECDOUBLE_Bytes]; /* fields: 1, 5, 8, 50 bits */
  46. uint16_t shorts[DECDOUBLE_Bytes/2];
  47. uint32_t words[DECDOUBLE_Bytes/4];
  48. #if DECUSE64
  49. uint64_t longs[DECDOUBLE_Bytes/8];
  50. #endif
  51. } decDouble;
  52. /* ---------------------------------------------------------------- */
  53. /* Routines -- implemented as decFloat routines in common files */
  54. /* ---------------------------------------------------------------- */
  55. #include "decDoubleSymbols.h"
  56. /* Utilities and conversions, extractors, etc.) */
  57. extern decDouble * decDoubleFromBCD(decDouble *, int32_t, const uint8_t *, int32_t);
  58. extern decDouble * decDoubleFromInt32(decDouble *, int32_t);
  59. extern decDouble * decDoubleFromPacked(decDouble *, int32_t, const uint8_t *);
  60. extern decDouble * decDoubleFromPackedChecked(decDouble *, int32_t, const uint8_t *);
  61. extern decDouble * decDoubleFromString(decDouble *, const char *, decContext *);
  62. extern decDouble * decDoubleFromUInt32(decDouble *, uint32_t);
  63. extern decDouble * decDoubleFromWider(decDouble *, const decQuad *, decContext *);
  64. extern int32_t decDoubleGetCoefficient(const decDouble *, uint8_t *);
  65. extern int32_t decDoubleGetExponent(const decDouble *);
  66. extern decDouble * decDoubleSetCoefficient(decDouble *, const uint8_t *, int32_t);
  67. extern decDouble * decDoubleSetExponent(decDouble *, decContext *, int32_t);
  68. extern void decDoubleShow(const decDouble *, const char *);
  69. extern int32_t decDoubleToBCD(const decDouble *, int32_t *, uint8_t *);
  70. extern char * decDoubleToEngString(const decDouble *, char *);
  71. extern int32_t decDoubleToInt32(const decDouble *, decContext *, enum rounding);
  72. extern int32_t decDoubleToInt32Exact(const decDouble *, decContext *, enum rounding);
  73. extern int32_t decDoubleToPacked(const decDouble *, int32_t *, uint8_t *);
  74. extern char * decDoubleToString(const decDouble *, char *);
  75. extern uint32_t decDoubleToUInt32(const decDouble *, decContext *, enum rounding);
  76. extern uint32_t decDoubleToUInt32Exact(const decDouble *, decContext *, enum rounding);
  77. extern decQuad * decDoubleToWider(const decDouble *, decQuad *);
  78. extern decDouble * decDoubleZero(decDouble *);
  79. /* Computational (result is a decDouble) */
  80. extern decDouble * decDoubleAbs(decDouble *, const decDouble *, decContext *);
  81. extern decDouble * decDoubleAdd(decDouble *, const decDouble *, const decDouble *, decContext *);
  82. extern decDouble * decDoubleAnd(decDouble *, const decDouble *, const decDouble *, decContext *);
  83. extern decDouble * decDoubleDivide(decDouble *, const decDouble *, const decDouble *, decContext *);
  84. extern decDouble * decDoubleDivideInteger(decDouble *, const decDouble *, const decDouble *, decContext *);
  85. extern decDouble * decDoubleFMA(decDouble *, const decDouble *, const decDouble *, const decDouble *, decContext *);
  86. extern decDouble * decDoubleInvert(decDouble *, const decDouble *, decContext *);
  87. extern decDouble * decDoubleLogB(decDouble *, const decDouble *, decContext *);
  88. extern decDouble * decDoubleMax(decDouble *, const decDouble *, const decDouble *, decContext *);
  89. extern decDouble * decDoubleMaxMag(decDouble *, const decDouble *, const decDouble *, decContext *);
  90. extern decDouble * decDoubleMin(decDouble *, const decDouble *, const decDouble *, decContext *);
  91. extern decDouble * decDoubleMinMag(decDouble *, const decDouble *, const decDouble *, decContext *);
  92. extern decDouble * decDoubleMinus(decDouble *, const decDouble *, decContext *);
  93. extern decDouble * decDoubleMultiply(decDouble *, const decDouble *, const decDouble *, decContext *);
  94. extern decDouble * decDoubleNextMinus(decDouble *, const decDouble *, decContext *);
  95. extern decDouble * decDoubleNextPlus(decDouble *, const decDouble *, decContext *);
  96. extern decDouble * decDoubleNextToward(decDouble *, const decDouble *, const decDouble *, decContext *);
  97. extern decDouble * decDoubleOr(decDouble *, const decDouble *, const decDouble *, decContext *);
  98. extern decDouble * decDoublePlus(decDouble *, const decDouble *, decContext *);
  99. extern decDouble * decDoubleQuantize(decDouble *, const decDouble *, const decDouble *, decContext *);
  100. extern decDouble * decDoubleReduce(decDouble *, const decDouble *, decContext *);
  101. extern decDouble * decDoubleRemainder(decDouble *, const decDouble *, const decDouble *, decContext *);
  102. extern decDouble * decDoubleRemainderNear(decDouble *, const decDouble *, const decDouble *, decContext *);
  103. extern decDouble * decDoubleRotate(decDouble *, const decDouble *, const decDouble *, decContext *);
  104. extern decDouble * decDoubleScaleB(decDouble *, const decDouble *, const decDouble *, decContext *);
  105. extern decDouble * decDoubleShift(decDouble *, const decDouble *, const decDouble *, decContext *);
  106. extern decDouble * decDoubleSubtract(decDouble *, const decDouble *, const decDouble *, decContext *);
  107. extern decDouble * decDoubleToIntegralValue(decDouble *, const decDouble *, decContext *, enum rounding);
  108. extern decDouble * decDoubleToIntegralExact(decDouble *, const decDouble *, decContext *);
  109. extern decDouble * decDoubleXor(decDouble *, const decDouble *, const decDouble *, decContext *);
  110. /* Comparisons */
  111. extern decDouble * decDoubleCompare(decDouble *, const decDouble *, const decDouble *, decContext *);
  112. extern decDouble * decDoubleCompareSignal(decDouble *, const decDouble *, const decDouble *, decContext *);
  113. extern decDouble * decDoubleCompareTotal(decDouble *, const decDouble *, const decDouble *);
  114. extern decDouble * decDoubleCompareTotalMag(decDouble *, const decDouble *, const decDouble *);
  115. /* Copies */
  116. extern decDouble * decDoubleCanonical(decDouble *, const decDouble *);
  117. extern decDouble * decDoubleCopy(decDouble *, const decDouble *);
  118. extern decDouble * decDoubleCopyAbs(decDouble *, const decDouble *);
  119. extern decDouble * decDoubleCopyNegate(decDouble *, const decDouble *);
  120. extern decDouble * decDoubleCopySign(decDouble *, const decDouble *, const decDouble *);
  121. /* Non-computational */
  122. extern enum decClass decDoubleClass(const decDouble *);
  123. extern const char * decDoubleClassString(const decDouble *);
  124. extern uint32_t decDoubleDigits(const decDouble *);
  125. extern uint32_t decDoubleIsCanonical(const decDouble *);
  126. extern uint32_t decDoubleIsFinite(const decDouble *);
  127. extern uint32_t decDoubleIsInfinite(const decDouble *);
  128. extern uint32_t decDoubleIsInteger(const decDouble *);
  129. extern uint32_t decDoubleIsNaN(const decDouble *);
  130. extern uint32_t decDoubleIsNormal(const decDouble *);
  131. extern uint32_t decDoubleIsSignaling(const decDouble *);
  132. extern uint32_t decDoubleIsSignalling(const decDouble *);
  133. extern uint32_t decDoubleIsSigned(const decDouble *);
  134. extern uint32_t decDoubleIsSubnormal(const decDouble *);
  135. extern uint32_t decDoubleIsZero(const decDouble *);
  136. extern uint32_t decDoubleRadix(const decDouble *);
  137. extern uint32_t decDoubleSameQuantum(const decDouble *, const decDouble *);
  138. extern const char * decDoubleVersion(void);
  139. /* decNumber conversions; these are implemented as macros so as not */
  140. /* to force a dependency on decimal64 and decNumber in decDouble. */
  141. /* decDoubleFromNumber returns a decimal64 * to avoid warnings. */
  142. #define decDoubleToNumber(dq, dn) decimal64ToNumber((decimal64 *)(dq), dn)
  143. #define decDoubleFromNumber(dq, dn, set) decimal64FromNumber((decimal64 *)(dq), dn, set)
  144. #endif