decQuad.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* decQuad module header for the decNumber C Library.
  2. Copyright (C) 2007-2022 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. /* decQuad.h -- Decimal 128-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. /* This include file is always included by decSingle and decDouble, */
  24. /* and therefore also holds useful constants used by all three. */
  25. #if !defined(DECQUAD)
  26. #define DECQUAD
  27. #define DECQUADNAME "decimalQuad" /* Short name */
  28. #define DECQUADTITLE "Decimal 128-bit datum" /* Verbose name */
  29. #define DECQUADAUTHOR "Mike Cowlishaw" /* Who to blame */
  30. /* parameters for decQuads */
  31. #define DECQUAD_Bytes 16 /* length */
  32. #define DECQUAD_Pmax 34 /* maximum precision (digits) */
  33. #define DECQUAD_Emin -6143 /* minimum adjusted exponent */
  34. #define DECQUAD_Emax 6144 /* maximum adjusted exponent */
  35. #define DECQUAD_EmaxD 4 /* maximum exponent digits */
  36. #define DECQUAD_Bias 6176 /* bias for the exponent */
  37. #define DECQUAD_String 43 /* maximum string length, +1 */
  38. #define DECQUAD_EconL 12 /* exponent continuation length */
  39. #define DECQUAD_Declets 11 /* count of declets */
  40. /* highest biased exponent (Elimit-1) */
  41. #define DECQUAD_Ehigh (DECQUAD_Emax + DECQUAD_Bias - (DECQUAD_Pmax-1))
  42. /* Required include */
  43. #include "decContext.h"
  44. /* The decQuad decimal 128-bit type, accessible by all sizes */
  45. typedef union {
  46. uint8_t bytes[DECQUAD_Bytes]; /* fields: 1, 5, 12, 110 bits */
  47. uint16_t shorts[DECQUAD_Bytes/2];
  48. uint32_t words[DECQUAD_Bytes/4];
  49. #if DECUSE64
  50. uint64_t longs[DECQUAD_Bytes/8];
  51. #endif
  52. } decQuad;
  53. /* ---------------------------------------------------------------- */
  54. /* Shared constants */
  55. /* ---------------------------------------------------------------- */
  56. /* sign and special values [top 32-bits; last two bits are don't-care
  57. for Infinity on input, last bit don't-care for NaNs] */
  58. #define DECFLOAT_Sign 0x80000000 /* 1 00000 00 Sign */
  59. #define DECFLOAT_NaN 0x7c000000 /* 0 11111 00 NaN generic */
  60. #define DECFLOAT_qNaN 0x7c000000 /* 0 11111 00 qNaN */
  61. #define DECFLOAT_sNaN 0x7e000000 /* 0 11111 10 sNaN */
  62. #define DECFLOAT_Inf 0x78000000 /* 0 11110 00 Infinity */
  63. #define DECFLOAT_MinSp 0x78000000 /* minimum special value */
  64. /* [specials are all >=MinSp] */
  65. /* Sign nibble constants */
  66. #if !defined(DECPPLUSALT)
  67. #define DECPPLUSALT 0x0A /* alternate plus nibble */
  68. #define DECPMINUSALT 0x0B /* alternate minus nibble */
  69. #define DECPPLUS 0x0C /* preferred plus nibble */
  70. #define DECPMINUS 0x0D /* preferred minus nibble */
  71. #define DECPPLUSALT2 0x0E /* alternate plus nibble */
  72. #define DECPUNSIGNED 0x0F /* alternate plus nibble (unsigned) */
  73. #endif
  74. /* ---------------------------------------------------------------- */
  75. /* Routines -- implemented as decFloat routines in common files */
  76. /* ---------------------------------------------------------------- */
  77. #include "decQuadSymbols.h"
  78. /* Utilities and conversions, extractors, etc.) */
  79. extern decQuad * decQuadFromBCD(decQuad *, int32_t, const uint8_t *, int32_t);
  80. extern decQuad * decQuadFromInt32(decQuad *, int32_t);
  81. extern decQuad * decQuadFromPacked(decQuad *, int32_t, const uint8_t *);
  82. extern decQuad * decQuadFromPackedChecked(decQuad *, int32_t, const uint8_t *);
  83. extern decQuad * decQuadFromString(decQuad *, const char *, decContext *);
  84. extern decQuad * decQuadFromUInt32(decQuad *, uint32_t);
  85. extern int32_t decQuadGetCoefficient(const decQuad *, uint8_t *);
  86. extern int32_t decQuadGetExponent(const decQuad *);
  87. extern decQuad * decQuadSetCoefficient(decQuad *, const uint8_t *, int32_t);
  88. extern decQuad * decQuadSetExponent(decQuad *, decContext *, int32_t);
  89. extern void decQuadShow(const decQuad *, const char *);
  90. extern int32_t decQuadToBCD(const decQuad *, int32_t *, uint8_t *);
  91. extern char * decQuadToEngString(const decQuad *, char *);
  92. extern int32_t decQuadToInt32(const decQuad *, decContext *, enum rounding);
  93. extern int32_t decQuadToInt32Exact(const decQuad *, decContext *, enum rounding);
  94. extern int32_t decQuadToPacked(const decQuad *, int32_t *, uint8_t *);
  95. extern char * decQuadToString(const decQuad *, char *);
  96. extern uint32_t decQuadToUInt32(const decQuad *, decContext *, enum rounding);
  97. extern uint32_t decQuadToUInt32Exact(const decQuad *, decContext *, enum rounding);
  98. extern decQuad * decQuadZero(decQuad *);
  99. /* Computational (result is a decQuad) */
  100. extern decQuad * decQuadAbs(decQuad *, const decQuad *, decContext *);
  101. extern decQuad * decQuadAdd(decQuad *, const decQuad *, const decQuad *, decContext *);
  102. extern decQuad * decQuadAnd(decQuad *, const decQuad *, const decQuad *, decContext *);
  103. extern decQuad * decQuadDivide(decQuad *, const decQuad *, const decQuad *, decContext *);
  104. extern decQuad * decQuadDivideInteger(decQuad *, const decQuad *, const decQuad *, decContext *);
  105. extern decQuad * decQuadFMA(decQuad *, const decQuad *, const decQuad *, const decQuad *, decContext *);
  106. extern decQuad * decQuadInvert(decQuad *, const decQuad *, decContext *);
  107. extern decQuad * decQuadLogB(decQuad *, const decQuad *, decContext *);
  108. extern decQuad * decQuadMax(decQuad *, const decQuad *, const decQuad *, decContext *);
  109. extern decQuad * decQuadMaxMag(decQuad *, const decQuad *, const decQuad *, decContext *);
  110. extern decQuad * decQuadMin(decQuad *, const decQuad *, const decQuad *, decContext *);
  111. extern decQuad * decQuadMinMag(decQuad *, const decQuad *, const decQuad *, decContext *);
  112. extern decQuad * decQuadMinus(decQuad *, const decQuad *, decContext *);
  113. extern decQuad * decQuadMultiply(decQuad *, const decQuad *, const decQuad *, decContext *);
  114. extern decQuad * decQuadNextMinus(decQuad *, const decQuad *, decContext *);
  115. extern decQuad * decQuadNextPlus(decQuad *, const decQuad *, decContext *);
  116. extern decQuad * decQuadNextToward(decQuad *, const decQuad *, const decQuad *, decContext *);
  117. extern decQuad * decQuadOr(decQuad *, const decQuad *, const decQuad *, decContext *);
  118. extern decQuad * decQuadPlus(decQuad *, const decQuad *, decContext *);
  119. extern decQuad * decQuadQuantize(decQuad *, const decQuad *, const decQuad *, decContext *);
  120. extern decQuad * decQuadReduce(decQuad *, const decQuad *, decContext *);
  121. extern decQuad * decQuadRemainder(decQuad *, const decQuad *, const decQuad *, decContext *);
  122. extern decQuad * decQuadRemainderNear(decQuad *, const decQuad *, const decQuad *, decContext *);
  123. extern decQuad * decQuadRotate(decQuad *, const decQuad *, const decQuad *, decContext *);
  124. extern decQuad * decQuadScaleB(decQuad *, const decQuad *, const decQuad *, decContext *);
  125. extern decQuad * decQuadShift(decQuad *, const decQuad *, const decQuad *, decContext *);
  126. extern decQuad * decQuadSubtract(decQuad *, const decQuad *, const decQuad *, decContext *);
  127. extern decQuad * decQuadToIntegralValue(decQuad *, const decQuad *, decContext *, enum rounding);
  128. extern decQuad * decQuadToIntegralExact(decQuad *, const decQuad *, decContext *);
  129. extern decQuad * decQuadXor(decQuad *, const decQuad *, const decQuad *, decContext *);
  130. /* Comparisons */
  131. extern decQuad * decQuadCompare(decQuad *, const decQuad *, const decQuad *, decContext *);
  132. extern decQuad * decQuadCompareSignal(decQuad *, const decQuad *, const decQuad *, decContext *);
  133. extern decQuad * decQuadCompareTotal(decQuad *, const decQuad *, const decQuad *);
  134. extern decQuad * decQuadCompareTotalMag(decQuad *, const decQuad *, const decQuad *);
  135. /* Copies */
  136. extern decQuad * decQuadCanonical(decQuad *, const decQuad *);
  137. extern decQuad * decQuadCopy(decQuad *, const decQuad *);
  138. extern decQuad * decQuadCopyAbs(decQuad *, const decQuad *);
  139. extern decQuad * decQuadCopyNegate(decQuad *, const decQuad *);
  140. extern decQuad * decQuadCopySign(decQuad *, const decQuad *, const decQuad *);
  141. /* Non-computational */
  142. extern enum decClass decQuadClass(const decQuad *);
  143. extern const char * decQuadClassString(const decQuad *);
  144. extern uint32_t decQuadDigits(const decQuad *);
  145. extern uint32_t decQuadIsCanonical(const decQuad *);
  146. extern uint32_t decQuadIsFinite(const decQuad *);
  147. extern uint32_t decQuadIsInteger(const decQuad *);
  148. extern uint32_t decQuadIsInfinite(const decQuad *);
  149. extern uint32_t decQuadIsNaN(const decQuad *);
  150. extern uint32_t decQuadIsNormal(const decQuad *);
  151. extern uint32_t decQuadIsSignaling(const decQuad *);
  152. extern uint32_t decQuadIsSignalling(const decQuad *);
  153. extern uint32_t decQuadIsSigned(const decQuad *);
  154. extern uint32_t decQuadIsSubnormal(const decQuad *);
  155. extern uint32_t decQuadIsZero(const decQuad *);
  156. extern uint32_t decQuadRadix(const decQuad *);
  157. extern uint32_t decQuadSameQuantum(const decQuad *, const decQuad *);
  158. extern const char * decQuadVersion(void);
  159. /* decNumber conversions; these are implemented as macros so as not */
  160. /* to force a dependency on decimal128 and decNumber in decQuad. */
  161. /* decQuadFromNumber returns a decimal128 * to avoid warnings. */
  162. #define decQuadToNumber(dq, dn) decimal128ToNumber((decimal128 *)(dq), dn)
  163. #define decQuadFromNumber(dq, dn, set) decimal128FromNumber((decimal128 *)(dq), dn, set)
  164. #endif