decimal32.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Decimal 32-bit format module header for the decNumber C Library.
  2. Copyright (C) 2005-2018 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 32-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. #if !defined(DECIMAL32)
  24. #define DECIMAL32
  25. #define DEC32NAME "decimal32" /* Short name */
  26. #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */
  27. #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */
  28. /* parameters for decimal32s */
  29. #define DECIMAL32_Bytes 4 /* length */
  30. #define DECIMAL32_Pmax 7 /* maximum precision (digits) */
  31. #define DECIMAL32_Emax 96 /* maximum adjusted exponent */
  32. #define DECIMAL32_Emin -95 /* minimum adjusted exponent */
  33. #define DECIMAL32_Bias 101 /* bias for the exponent */
  34. #define DECIMAL32_String 15 /* maximum string length, +1 */
  35. #define DECIMAL32_EconL 6 /* exp. continuation length */
  36. /* highest biased exponent (Elimit-1) */
  37. #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
  38. /* check enough digits, if pre-defined */
  39. #if defined(DECNUMDIGITS)
  40. #if (DECNUMDIGITS<DECIMAL32_Pmax)
  41. #error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use
  42. #endif
  43. #endif
  44. #ifndef DECNUMDIGITS
  45. #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/
  46. #endif
  47. #ifndef DECNUMBER
  48. #include "decNumber.h" /* context and number library */
  49. #endif
  50. /* Decimal 32-bit type, accessible by bytes */
  51. typedef struct {
  52. uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/
  53. } decimal32;
  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 "decimal32Symbols.h"
  65. #ifdef __cplusplus
  66. extern "C" {
  67. #endif
  68. /* String conversions */
  69. decimal32 * decimal32FromString(decimal32 *, const char *, decContext *);
  70. char * decimal32ToString(const decimal32 *, char *);
  71. char * decimal32ToEngString(const decimal32 *, char *);
  72. /* decNumber conversions */
  73. decimal32 * decimal32FromNumber(decimal32 *, const decNumber *,
  74. decContext *);
  75. decNumber * decimal32ToNumber(const decimal32 *, decNumber *);
  76. /* Format-dependent utilities */
  77. uint32_t decimal32IsCanonical(const decimal32 *);
  78. decimal32 * decimal32Canonical(decimal32 *, const decimal32 *);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif