decimal32.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ------------------------------------------------------------------ */
  2. /* Decimal 32-bit format module header */
  3. /* ------------------------------------------------------------------ */
  4. /* Copyright (c) IBM Corporation, 2000, 2006. All rights reserved. */
  5. /* */
  6. /* This software is made available under the terms of the */
  7. /* ICU License -- ICU 1.8.1 and later. */
  8. /* */
  9. /* The description and User's Guide ("The decNumber C Library") for */
  10. /* this software is called decNumber.pdf. This document is */
  11. /* available, together with arithmetic and format specifications, */
  12. /* testcases, and Web links, on the General Decimal Arithmetic page. */
  13. /* */
  14. /* Please send comments, suggestions, and corrections to the author: */
  15. /* [email protected] */
  16. /* Mike Cowlishaw, IBM Fellow */
  17. /* IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK */
  18. /* ------------------------------------------------------------------ */
  19. #if !defined(DECIMAL32)
  20. #define DECIMAL32
  21. #define DEC32NAME "decimal32" /* Short name */
  22. #define DEC32FULLNAME "Decimal 32-bit Number" /* Verbose name */
  23. #define DEC32AUTHOR "Mike Cowlishaw" /* Who to blame */
  24. /* parameters for decimal32s */
  25. #define DECIMAL32_Bytes 4 /* length */
  26. #define DECIMAL32_Pmax 7 /* maximum precision (digits) */
  27. #define DECIMAL32_Emax 96 /* maximum adjusted exponent */
  28. #define DECIMAL32_Emin -95 /* minimum adjusted exponent */
  29. #define DECIMAL32_Bias 101 /* bias for the exponent */
  30. #define DECIMAL32_String 15 /* maximum string length, +1 */
  31. #define DECIMAL32_EconL 6 /* exp. continuation length */
  32. /* highest biased exponent (Elimit-1) */
  33. #define DECIMAL32_Ehigh (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
  34. /* check enough digits, if pre-defined */
  35. #if defined(DECNUMDIGITS)
  36. #if (DECNUMDIGITS<DECIMAL32_Pmax)
  37. #error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use
  38. #endif
  39. #endif
  40. #ifndef DECNUMDIGITS
  41. #define DECNUMDIGITS DECIMAL32_Pmax /* size if not already defined*/
  42. #endif
  43. #ifndef DECNUMBER
  44. #include "decNumber.h" /* context and number library */
  45. #endif
  46. /* Decimal 32-bit type, accessible by bytes */
  47. typedef struct {
  48. uint8_t bytes[DECIMAL32_Bytes]; /* decimal32: 1, 5, 6, 20 bits*/
  49. } decimal32;
  50. /* special values [top byte excluding sign bit; last two bits are */
  51. /* don't-care for Infinity on input, last bit don't-care for NaN] */
  52. #if !defined(DECIMAL_NaN)
  53. #define DECIMAL_NaN 0x7c /* 0 11111 00 NaN */
  54. #define DECIMAL_sNaN 0x7e /* 0 11111 10 sNaN */
  55. #define DECIMAL_Inf 0x78 /* 0 11110 00 Infinity */
  56. #endif
  57. /* ---------------------------------------------------------------- */
  58. /* Routines */
  59. /* ---------------------------------------------------------------- */
  60. /* String conversions */
  61. decimal32 * decimal32FromString(decimal32 *, const char *, decContext *);
  62. char * decimal32ToString(const decimal32 *, char *);
  63. char * decimal32ToEngString(const decimal32 *, char *);
  64. /* decNumber conversions */
  65. decimal32 * decimal32FromNumber(decimal32 *, const decNumber *,
  66. decContext *);
  67. decNumber * decimal32ToNumber(const decimal32 *, decNumber *);
  68. /* Format-dependent utilities */
  69. uint32_t decimal32IsCanonical(const decimal32 *);
  70. decimal32 * decimal32Canonical(decimal32 *, const decimal32 *);
  71. #endif