bignum.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* -*-C-*-
  2. $Id: bignum.h,v 9.28 1992/09/18 16:52:34 jinx Exp $
  3. Copyright (c) 1989-1992 Massachusetts Institute of Technology
  4. This material was developed by the Scheme project at the Massachusetts
  5. Institute of Technology, Department of Electrical Engineering and
  6. Computer Science. Permission to copy and modify this software, to
  7. redistribute either the original software or a modified version, and
  8. to use this software for any purpose is granted, subject to the
  9. following restrictions and understandings.
  10. 1. Any copy made of this software must include this copyright notice
  11. in full.
  12. 2. Users of this software agree to make their best efforts (a) to
  13. return to the MIT Scheme project any improvements or extensions that
  14. they make, so that these may be included in future releases; and (b)
  15. to inform MIT of noteworthy uses of this software.
  16. 3. All materials developed as a consequence of the use of this
  17. software shall duly acknowledge such use, in accordance with the usual
  18. standards of acknowledging credit in academic research.
  19. 4. MIT has made no warrantee or representation that the operation of
  20. this software will be error-free, and MIT is under no obligation to
  21. provide any services, by way of maintenance, update, or otherwise.
  22. 5. In conjunction with products arising from the use of this material,
  23. there shall be no use of the name of the Massachusetts Institute of
  24. Technology nor of any adaptation thereof in any advertising,
  25. promotional, or sales literature without prior written consent from
  26. MIT in each case. */
  27. /* External Interface to Bignum Code */
  28. /* The `unsigned long' type is used for the conversion procedures
  29. `bignum_to_long' and `long_to_bignum'. Older implementations of C
  30. don't support this type; if you have such an implementation you can
  31. disable these procedures using the following flag (alternatively
  32. you could write alternate versions that don't require this type). */
  33. /* #define BIGNUM_NO_ULONG */
  34. #include "scheme48.h"
  35. typedef void * bignum_type;
  36. #define BIGNUM_OUT_OF_BAND ((bignum_type) 0)
  37. enum bignum_comparison
  38. {
  39. bignum_comparison_equal = 0,
  40. bignum_comparison_less = -1,
  41. bignum_comparison_greater = 1
  42. };
  43. typedef void * bignum_procedure_context;
  44. extern void s48_bignum_make_cached_constants();
  45. extern int s48_bignum_equal_p(bignum_type, bignum_type);
  46. extern enum bignum_comparison s48_bignum_test(bignum_type);
  47. extern enum bignum_comparison s48_bignum_compare(bignum_type, bignum_type);
  48. extern bignum_type s48_bignum_add(bignum_type, bignum_type);
  49. extern bignum_type s48_bignum_subtract(bignum_type, bignum_type);
  50. extern bignum_type s48_bignum_negate(bignum_type);
  51. extern bignum_type s48_bignum_multiply(bignum_type, bignum_type);
  52. extern int s48_bignum_divide(bignum_type numerator, bignum_type denominator,
  53. void * quotient, void * remainder);
  54. extern bignum_type s48_bignum_quotient(bignum_type, bignum_type);
  55. extern bignum_type s48_bignum_remainder(bignum_type, bignum_type);
  56. extern bignum_type s48_long_to_bignum(long);
  57. extern bignum_type s48_ulong_to_bignum(unsigned long);
  58. extern long s48_bignum_to_long(bignum_type);
  59. extern unsigned long s48_bignum_to_ulong(bignum_type);
  60. extern bignum_type s48_double_to_bignum(double);
  61. extern double s48_bignum_to_double(bignum_type);
  62. extern int s48_bignum_fits_in_word_p(bignum_type, long word_length,
  63. int twos_complement_p);
  64. extern bignum_type s48_bignum_length_in_bits(bignum_type);
  65. extern bignum_type s48_bignum_length_upper_limit(void);
  66. extern bignum_type s48_digit_stream_to_bignum
  67. (unsigned int n_digits,
  68. unsigned int (*producer(bignum_procedure_context)),
  69. bignum_procedure_context context,
  70. unsigned int radix,
  71. int negative_p);
  72. extern void s48_bignum_to_digit_stream
  73. (bignum_type,
  74. unsigned int radix,
  75. void *consumer(bignum_procedure_context, long),
  76. bignum_procedure_context context);
  77. extern long s48_bignum_max_digit_stream_radix(void);
  78. /* Added bitwise operators. */
  79. extern bignum_type s48_bignum_bitwise_not(bignum_type),
  80. s48_bignum_arithmetic_shift(bignum_type, long),
  81. s48_bignum_bitwise_and(bignum_type, bignum_type),
  82. s48_bignum_bitwise_ior(bignum_type, bignum_type),
  83. s48_bignum_bitwise_xor(bignum_type, bignum_type);
  84. extern int s48_bignum_oddp(bignum_type);
  85. extern long s48_bignum_bit_count(bignum_type);