AbaKus – a complex calculator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

170 lines
4.4 KiB

  1. /* number.h: Arbitrary precision numbers header file. */
  2. /*
  3. Copyright (C) 1991, 1992, 1993, 1994, 1997, 2000 Free Software Foundation, Inc.
  4. This program 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 2 of the License , or
  7. (at your option) any later version.
  8. This program 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 this program; see the file COPYING. If not, write to:
  14. The Free Software Foundation, Inc.
  15. 51 Franklin Street, Fifth Floor
  16. Boston, MA 02110-1301 USA.
  17. You may contact the author by:
  18. e-mail: philnelson@acm.org
  19. us-mail: Philip A. Nelson
  20. Computer Science Department, 9062
  21. Western Washington University
  22. Bellingham, WA 98226-9062
  23. *************************************************************************/
  24. #ifndef _NUMBER_H_
  25. #define _NUMBER_H_
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #undef _PROTOTYPE
  30. #ifndef NUMBER__STDC__
  31. #define NUMBER__STDC__
  32. #endif
  33. typedef enum {PLUS, MINUS} sign;
  34. typedef struct bc_struct *bc_num;
  35. typedef struct bc_struct
  36. {
  37. sign n_sign;
  38. int n_len; /* The number of digits before the decimal point. */
  39. int n_scale; /* The number of digits after the decimal point. */
  40. int n_refs; /* The number of pointers to this number. */
  41. bc_num n_next; /* Linked list for available list. */
  42. char *n_ptr; /* The pointer to the actual storage.
  43. If NULL, n_value points to the inside of
  44. another number (bc_multiply...) and should
  45. not be "freed." */
  46. char *n_value; /* The number. Not zero char terminated.
  47. May not point to the same place as n_ptr as
  48. in the case of leading zeros generated. */
  49. } bc_struct;
  50. /* The base used in storing the numbers in n_value above.
  51. Currently this MUST be 10. */
  52. #define BASE 10
  53. /* Some useful macros and constants. */
  54. #define CH_VAL(c) (c - '0')
  55. #define BCD_CHAR(d) (d + '0')
  56. #ifdef MIN
  57. #undef MIN
  58. #undef MAX
  59. #endif
  60. #define MAX(a,b) ((a)>(b)?(a):(b))
  61. #define MIN(a,b) ((a)>(b)?(b):(a))
  62. #define ODD(a) ((a)&1)
  63. #ifndef TRUE
  64. #define TRUE 1
  65. #define FALSE 0
  66. #endif
  67. #ifndef LONG_MAX
  68. #define LONG_MAX 0x7ffffff
  69. #endif
  70. /* Global numbers. */
  71. extern bc_num _zero_;
  72. extern bc_num _one_;
  73. extern bc_num _two_;
  74. /* Function Prototypes */
  75. /* Define the _PROTOTYPE macro if it is needed. */
  76. #ifndef _PROTOTYPE
  77. #ifdef NUMBER__STDC__
  78. #define _PROTOTYPE(func, args) func args
  79. #else
  80. #define _PROTOTYPE(func, args) func()
  81. #endif
  82. #endif
  83. _PROTOTYPE(void bc_init_numbers, (void));
  84. _PROTOTYPE(bc_num bc_new_num, (int length, int scale));
  85. _PROTOTYPE(void bc_free_num, (bc_num *num));
  86. _PROTOTYPE(bc_num bc_copy_num, (bc_num num));
  87. _PROTOTYPE(void bc_init_num, (bc_num *num));
  88. _PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale));
  89. _PROTOTYPE(char *bc_num2str, (bc_num num));
  90. _PROTOTYPE(void bc_int2num, (bc_num *num, int val));
  91. _PROTOTYPE(long bc_num2long, (bc_num num));
  92. _PROTOTYPE(int bc_compare, (bc_num n1, bc_num n2));
  93. _PROTOTYPE(char bc_is_zero, (bc_num num));
  94. _PROTOTYPE(char bc_is_near_zero, (bc_num num, int scale));
  95. _PROTOTYPE(char bc_is_neg, (bc_num num));
  96. _PROTOTYPE(void bc_add, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
  97. _PROTOTYPE(void bc_sub, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
  98. _PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale));
  99. _PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale));
  100. _PROTOTYPE(int bc_modulo, (bc_num num1, bc_num num2, bc_num *result,
  101. int scale));
  102. _PROTOTYPE(int bc_divmod, (bc_num num1, bc_num num2, bc_num *quot,
  103. bc_num *rem, int scale));
  104. _PROTOTYPE(int bc_raisemod, (bc_num base, bc_num expo, bc_num mod,
  105. bc_num *result, int scale));
  106. _PROTOTYPE(void bc_raise, (bc_num num1, bc_num num2, bc_num *result,
  107. int scale));
  108. _PROTOTYPE(int bc_sqrt, (bc_num *num, int scale));
  109. _PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
  110. int leading_zero));
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. #endif
  115. // vim: set et sw=2 ts=8: