bignum.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* -*-C-*-
  2. $Id: bignum.h,v 9.28 1992/09/18 16:52:34 jinx Exp $
  3. Copyright 1986,1987,1988,1989,1992,2004 Massachusetts Institute of Technology
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above
  10. copyright notice, this list of conditions and the following
  11. disclaimer in the documentation and/or other materials provided
  12. with the distribution.
  13. 3. The name of the author may not be used to endorse or promote
  14. products derived from this software without specific prior
  15. written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  20. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  25. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /* License changed to modified BSD by cph on 2004-11-08. */
  29. /* External Interface to Bignum Code */
  30. /* The `unsigned long' type is used for the conversion procedures
  31. `bignum_to_long' and `long_to_bignum'. Older implementations of C
  32. don't support this type; if you have such an implementation you can
  33. disable these procedures using the following flag (alternatively
  34. you could write alternate versions that don't require this type). */
  35. /* #define BIGNUM_NO_ULONG */
  36. #include "scheme48.h"
  37. typedef void * bignum_type;
  38. #define BIGNUM_OUT_OF_BAND ((bignum_type) 0)
  39. enum bignum_comparison
  40. {
  41. bignum_comparison_equal = 0,
  42. bignum_comparison_less = -1,
  43. bignum_comparison_greater = 1
  44. };
  45. typedef void * bignum_procedure_context;
  46. extern void s48_bignum_make_cached_constants();
  47. extern int s48_bignum_equal_p(bignum_type, bignum_type);
  48. extern enum bignum_comparison s48_bignum_test(bignum_type);
  49. extern enum bignum_comparison s48_bignum_compare(bignum_type, bignum_type);
  50. extern bignum_type s48_bignum_add(bignum_type, bignum_type);
  51. extern bignum_type s48_bignum_subtract(bignum_type, bignum_type);
  52. extern bignum_type s48_bignum_negate(bignum_type);
  53. extern bignum_type s48_bignum_multiply(bignum_type, bignum_type);
  54. extern int s48_bignum_divide(bignum_type numerator, bignum_type denominator,
  55. void * quotient, void * remainder);
  56. extern bignum_type s48_bignum_quotient(bignum_type, bignum_type);
  57. extern bignum_type s48_bignum_remainder(bignum_type, bignum_type);
  58. extern bignum_type s48_long_to_bignum(long);
  59. extern bignum_type s48_ulong_to_bignum(unsigned long);
  60. extern long s48_bignum_to_long(bignum_type);
  61. extern unsigned long s48_bignum_to_ulong(bignum_type);
  62. extern bignum_type s48_double_to_bignum(double);
  63. extern double s48_bignum_to_double(bignum_type);
  64. extern int s48_bignum_fits_in_word_p(bignum_type, long word_length,
  65. int twos_complement_p);
  66. extern bignum_type s48_bignum_length_in_bits(bignum_type);
  67. extern bignum_type s48_bignum_length_upper_limit(void);
  68. extern bignum_type s48_digit_stream_to_bignum
  69. (unsigned int n_digits,
  70. unsigned int (*producer)(bignum_procedure_context),
  71. bignum_procedure_context context,
  72. unsigned int radix,
  73. int negative_p);
  74. extern void s48_bignum_to_digit_stream
  75. (bignum_type,
  76. unsigned int radix,
  77. void (*consumer)(bignum_procedure_context, long),
  78. bignum_procedure_context context);
  79. extern long s48_bignum_max_digit_stream_radix(void);
  80. /* Added bitwise operators. */
  81. extern bignum_type s48_bignum_bitwise_not(bignum_type),
  82. s48_bignum_arithmetic_shift(bignum_type, long),
  83. s48_bignum_bitwise_and(bignum_type, bignum_type),
  84. s48_bignum_bitwise_ior(bignum_type, bignum_type),
  85. s48_bignum_bitwise_xor(bignum_type, bignum_type);
  86. extern int s48_bignum_oddp(bignum_type);
  87. extern long s48_bignum_bit_count(bignum_type);