flonum.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* flonum.h - Floating point package
  2. Copyright (C) 1987-2022 Free Software Foundation, Inc.
  3. This file is part of GAS, the GNU Assembler.
  4. GAS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GAS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GAS; see the file COPYING. If not, write to the Free
  14. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  15. 02110-1301, USA. */
  16. /***********************************************************************\
  17. * *
  18. * Arbitrary-precision floating point arithmetic. *
  19. * *
  20. * *
  21. * Notation: a floating point number is expressed as *
  22. * MANTISSA * (2 ** EXPONENT). *
  23. * *
  24. * If this offends more traditional mathematicians, then *
  25. * please tell me your nomenclature for flonums! *
  26. * *
  27. \***********************************************************************/
  28. #include "bignum.h"
  29. /***********************************************************************\
  30. * *
  31. * Variable precision floating point numbers. *
  32. * *
  33. * Exponent is the place value of the low littlenum. E.g.: *
  34. * If 0: low points to the units littlenum. *
  35. * If 1: low points to the LITTLENUM_RADIX littlenum. *
  36. * If -1: low points to the 1/LITTLENUM_RADIX littlenum. *
  37. * *
  38. \***********************************************************************/
  39. /* JF: A sign value of 0 means we have been asked to assemble NaN
  40. A sign value of 'P' means we've been asked to assemble +Inf
  41. A sign value of 'N' means we've been asked to assemble -Inf
  42. A sign value of 'Q' means we've been asked to assemble +QNaN
  43. A sign value of 'q' means we've been asked to assemble -QNaN
  44. A sign value of 'S' means we've been asked to assemble +SNaN
  45. A sign value of 's' means we've been asked to assemble -SNaN
  46. */
  47. struct FLONUM_STRUCT {
  48. LITTLENUM_TYPE *low; /* low order littlenum of a bignum */
  49. LITTLENUM_TYPE *high; /* high order littlenum of a bignum */
  50. LITTLENUM_TYPE *leader; /* -> 1st non-zero littlenum */
  51. /* If flonum is 0.0, leader==low-1 */
  52. long exponent; /* base LITTLENUM_RADIX */
  53. char sign; /* '+' or '-' */
  54. };
  55. typedef struct FLONUM_STRUCT FLONUM_TYPE;
  56. /***********************************************************************\
  57. * *
  58. * Since we can (& do) meet with exponents like 10^5000, it *
  59. * is silly to make a table of ~ 10,000 entries, one for each *
  60. * power of 10. We keep a table where item [n] is a struct *
  61. * FLONUM_FLOATING_POINT representing 10^(2^n). We then *
  62. * multiply appropriate entries from this table to get any *
  63. * particular power of 10. For the example of 10^5000, a table *
  64. * of just 25 entries suffices: 10^(2^-12)...10^(2^+12). *
  65. * *
  66. \***********************************************************************/
  67. extern const FLONUM_TYPE flonum_positive_powers_of_ten[];
  68. extern const FLONUM_TYPE flonum_negative_powers_of_ten[];
  69. extern const int table_size_of_flonum_powers_of_ten;
  70. /* Flonum_XXX_powers_of_ten[] table has legal indices from 0 to
  71. + this number inclusive. */
  72. /***********************************************************************\
  73. * *
  74. * Declare worker functions. *
  75. * *
  76. \***********************************************************************/
  77. int atof_generic (char **address_of_string_pointer,
  78. const char *string_of_decimal_marks,
  79. const char *string_of_decimal_exponent_marks,
  80. FLONUM_TYPE * address_of_generic_floating_point_number);
  81. void flonum_copy (FLONUM_TYPE * in, FLONUM_TYPE * out);
  82. void flonum_multip (const FLONUM_TYPE * a, const FLONUM_TYPE * b,
  83. FLONUM_TYPE * product);
  84. /***********************************************************************\
  85. * *
  86. * Declare error codes. *
  87. * *
  88. \***********************************************************************/
  89. #define ERROR_EXPONENT_OVERFLOW (2)