decimal128.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Decimal 128-bit format module header for the decNumber C Library.
  2. Copyright (C) 2005-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. /* Decimal 128-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. #if !defined(DECIMAL128)
  24. #define DECIMAL128
  25. #define DEC128NAME "decimal128" /* Short name */
  26. #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
  27. #define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */
  28. /* parameters for decimal128s */
  29. #define DECIMAL128_Bytes 16 /* length */
  30. #define DECIMAL128_Pmax 34 /* maximum precision (digits) */
  31. #define DECIMAL128_Emax 6144 /* maximum adjusted exponent */
  32. #define DECIMAL128_Emin -6143 /* minimum adjusted exponent */
  33. #define DECIMAL128_Bias 6176 /* bias for the exponent */
  34. #define DECIMAL128_String 43 /* maximum string length, +1 */
  35. #define DECIMAL128_EconL 12 /* exp. continuation length */
  36. /* highest biased exponent (Elimit-1) */
  37. #define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
  38. /* check enough digits, if pre-defined */
  39. #if defined(DECNUMDIGITS)
  40. #if (DECNUMDIGITS<DECIMAL128_Pmax)
  41. #error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
  42. #endif
  43. #endif
  44. #ifndef DECNUMDIGITS
  45. #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/
  46. #endif
  47. #ifndef DECNUMBER
  48. #include "decNumber.h" /* context and number library */
  49. #endif
  50. /* Decimal 128-bit type, accessible by bytes */
  51. typedef struct {
  52. uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
  53. } decimal128;
  54. /* special values [top byte excluding sign bit; last two bits are */
  55. /* don't-care for Infinity on input, last bit don't-care for NaN] */
  56. #if !defined(DECIMAL_NaN)
  57. #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
  58. #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
  59. #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
  60. #endif
  61. #include "decimal128Local.h"
  62. /* ---------------------------------------------------------------- */
  63. /* Routines */
  64. /* ---------------------------------------------------------------- */
  65. #include "decimal128Symbols.h"
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. /* String conversions */
  70. decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
  71. char * decimal128ToString(const decimal128 *, char *);
  72. char * decimal128ToEngString(const decimal128 *, char *);
  73. /* decNumber conversions */
  74. decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
  75. decContext *);
  76. decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
  77. /* Format-dependent utilities */
  78. uint32_t decimal128IsCanonical(const decimal128 *);
  79. decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif