decSingle.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* decSingle 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. /* decSingle.h -- Decimal 32-bit format module header */
  22. /* ------------------------------------------------------------------ */
  23. #if !defined(DECSINGLE)
  24. #define DECSINGLE
  25. #define DECSINGLENAME "decSingle" /* Short name */
  26. #define DECSINGLETITLE "Decimal 32-bit datum" /* Verbose name */
  27. #define DECSINGLEAUTHOR "Mike Cowlishaw" /* Who to blame */
  28. /* parameters for decSingles */
  29. #define DECSINGLE_Bytes 4 /* length */
  30. #define DECSINGLE_Pmax 7 /* maximum precision (digits) */
  31. #define DECSINGLE_Emin -95 /* minimum adjusted exponent */
  32. #define DECSINGLE_Emax 96 /* maximum adjusted exponent */
  33. #define DECSINGLE_EmaxD 3 /* maximum exponent digits */
  34. #define DECSINGLE_Bias 101 /* bias for the exponent */
  35. #define DECSINGLE_String 16 /* maximum string length, +1 */
  36. #define DECSINGLE_EconL 6 /* exponent continuation length */
  37. #define DECSINGLE_Declets 2 /* count of declets */
  38. /* highest biased exponent (Elimit-1) */
  39. #define DECSINGLE_Ehigh (DECSINGLE_Emax + DECSINGLE_Bias - (DECSINGLE_Pmax-1))
  40. /* Required includes */
  41. #include "decContext.h"
  42. #include "decQuad.h"
  43. #include "decDouble.h"
  44. /* The decSingle decimal 32-bit type, accessible by all sizes */
  45. typedef union {
  46. uint8_t bytes[DECSINGLE_Bytes]; /* fields: 1, 5, 6, 20 bits */
  47. uint16_t shorts[DECSINGLE_Bytes/2];
  48. uint32_t words[DECSINGLE_Bytes/4];
  49. } decSingle;
  50. /* ---------------------------------------------------------------- */
  51. /* Routines -- implemented as decFloat routines in common files */
  52. /* ---------------------------------------------------------------- */
  53. #include "decSingleSymbols.h"
  54. /* Utilities (binary argument(s) or result, extractors, etc.) */
  55. extern decSingle * decSingleFromBCD(decSingle *, int32_t, const uint8_t *, int32_t);
  56. extern decSingle * decSingleFromPacked(decSingle *, int32_t, const uint8_t *);
  57. extern decSingle * decSingleFromPackedChecked(decSingle *, int32_t, const uint8_t *);
  58. extern decSingle * decSingleFromString(decSingle *, const char *, decContext *);
  59. extern decSingle * decSingleFromWider(decSingle *, const decDouble *, decContext *);
  60. extern int32_t decSingleGetCoefficient(const decSingle *, uint8_t *);
  61. extern int32_t decSingleGetExponent(const decSingle *);
  62. extern decSingle * decSingleSetCoefficient(decSingle *, const uint8_t *, int32_t);
  63. extern decSingle * decSingleSetExponent(decSingle *, decContext *, int32_t);
  64. extern void decSingleShow(const decSingle *, const char *);
  65. extern int32_t decSingleToBCD(const decSingle *, int32_t *, uint8_t *);
  66. extern char * decSingleToEngString(const decSingle *, char *);
  67. extern int32_t decSingleToPacked(const decSingle *, int32_t *, uint8_t *);
  68. extern char * decSingleToString(const decSingle *, char *);
  69. extern decDouble * decSingleToWider(const decSingle *, decDouble *);
  70. extern decSingle * decSingleZero(decSingle *);
  71. /* (No Arithmetic routines for decSingle) */
  72. /* Non-computational */
  73. extern uint32_t decSingleRadix(const decSingle *);
  74. extern const char * decSingleVersion(void);
  75. /* decNumber conversions; these are implemented as macros so as not */
  76. /* to force a dependency on decimal32 and decNumber in decSingle. */
  77. /* decSingleFromNumber returns a decimal32 * to avoid warnings. */
  78. #define decSingleToNumber(dq, dn) decimal32ToNumber((decimal32 *)(dq), dn)
  79. #define decSingleFromNumber(dq, dn, set) decimal32FromNumber((decimal32 *)(dq), dn, set)
  80. #endif