2
0

decimal128.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ------------------------------------------------------------------ */
  2. /* Decimal 128-bit format module header */
  3. /* ------------------------------------------------------------------ */
  4. /* Copyright (c) IBM Corporation, 2000, 2005. 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(DECIMAL128)
  20. #define DECIMAL128
  21. #define DEC128NAME "decimal128" /* Short name */
  22. #define DEC128FULLNAME "Decimal 128-bit Number" /* Verbose name */
  23. #define DEC128AUTHOR "Mike Cowlishaw" /* Who to blame */
  24. /* parameters for decimal128s */
  25. #define DECIMAL128_Bytes 16 /* length */
  26. #define DECIMAL128_Pmax 34 /* maximum precision (digits) */
  27. #define DECIMAL128_Emax 6144 /* maximum adjusted exponent */
  28. #define DECIMAL128_Emin -6143 /* minimum adjusted exponent */
  29. #define DECIMAL128_Bias 6176 /* bias for the exponent */
  30. #define DECIMAL128_String 43 /* maximum string length, +1 */
  31. #define DECIMAL128_EconL 12 /* exp. continuation length */
  32. /* highest biased exponent (Elimit-1) */
  33. #define DECIMAL128_Ehigh (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
  34. /* check enough digits, if pre-defined */
  35. #if defined(DECNUMDIGITS)
  36. #if (DECNUMDIGITS<DECIMAL128_Pmax)
  37. #error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
  38. #endif
  39. #endif
  40. #ifndef DECNUMDIGITS
  41. #define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined*/
  42. #endif
  43. #ifndef DECNUMBER
  44. #include "decNumber.h" /* context and number library */
  45. #endif
  46. /* Decimal 128-bit type, accessible by bytes */
  47. typedef struct {
  48. uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
  49. } decimal128;
  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. decimal128 * decimal128FromString(decimal128 *, const char *, decContext *);
  62. char * decimal128ToString(const decimal128 *, char *);
  63. char * decimal128ToEngString(const decimal128 *, char *);
  64. /* decNumber conversions */
  65. decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
  66. decContext *);
  67. decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
  68. /* Format-dependent utilities */
  69. uint32_t decimal128IsCanonical(const decimal128 *);
  70. decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
  71. #endif