decimal64.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Decimal 64-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 64-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. #if !defined(DECIMAL64)
  24. #define DECIMAL64
  25. #define DEC64NAME "decimal64" /* Short name */
  26. #define DEC64FULLNAME "Decimal 64-bit Number" /* Verbose name */
  27. #define DEC64AUTHOR "Mike Cowlishaw" /* Who to blame */
  28. /* parameters for decimal64s */
  29. #define DECIMAL64_Bytes 8 /* length */
  30. #define DECIMAL64_Pmax 16 /* maximum precision (digits) */
  31. #define DECIMAL64_Emax 384 /* maximum adjusted exponent */
  32. #define DECIMAL64_Emin -383 /* minimum adjusted exponent */
  33. #define DECIMAL64_Bias 398 /* bias for the exponent */
  34. #define DECIMAL64_String 24 /* maximum string length, +1 */
  35. #define DECIMAL64_EconL 8 /* exp. continuation length */
  36. /* highest biased exponent (Elimit-1) */
  37. #define DECIMAL64_Ehigh (DECIMAL64_Emax+DECIMAL64_Bias-DECIMAL64_Pmax+1)
  38. /* check enough digits, if pre-defined */
  39. #if defined(DECNUMDIGITS)
  40. #if (DECNUMDIGITS<DECIMAL64_Pmax)
  41. #error decimal64.h needs pre-defined DECNUMDIGITS>=16 for safe use
  42. #endif
  43. #endif
  44. #ifndef DECNUMDIGITS
  45. #define DECNUMDIGITS DECIMAL64_Pmax /* size if not already defined*/
  46. #endif
  47. #ifndef DECNUMBER
  48. #include "decNumber.h" /* context and number library */
  49. #endif
  50. /* Decimal 64-bit type, accessible by bytes */
  51. typedef struct {
  52. uint8_t bytes[DECIMAL64_Bytes]; /* decimal64: 1, 5, 8, 50 bits*/
  53. } decimal64;
  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. /* ---------------------------------------------------------------- */
  62. /* Routines */
  63. /* ---------------------------------------------------------------- */
  64. #include "decimal64Symbols.h"
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /* String conversions */
  69. decimal64 * decimal64FromString(decimal64 *, const char *, decContext *);
  70. char * decimal64ToString(const decimal64 *, char *);
  71. char * decimal64ToEngString(const decimal64 *, char *);
  72. /* decNumber conversions */
  73. decimal64 * decimal64FromNumber(decimal64 *, const decNumber *,
  74. decContext *);
  75. decNumber * decimal64ToNumber(const decimal64 *, decNumber *);
  76. /* Format-dependent utilities */
  77. uint32_t decimal64IsCanonical(const decimal64 *);
  78. decimal64 * decimal64Canonical(decimal64 *, const decimal64 *);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif