arith.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* arith.h Copyright (C) Codemist Ltd, 1990-1995 */
  2. /* Signature: 05ee46ce 07-Mar-2000 */
  3. #ifndef header_arith_h
  4. #define header_arith_h 1
  5. #define TWO_32 4294967296.0 /* 2^32 */
  6. #define TWO_31 2147483648.0 /* 2^31 */
  7. #define TWO_24 16777216.0 /* 2^24 */
  8. #define TWO_22 4194304.0 /* 2^22 */
  9. #define TWO_21 2097152.0 /* 2^21 */
  10. #define TWO_20 1048576.0 /* 2^20 */
  11. #define M2_31_1 -2147483649.0 /* -(2^31 + 1) */
  12. #define _pi 3.14159265358979323846
  13. #define _half_pi 1.57079632679489661923
  14. #define boole_clr 0
  15. #define boole_and 1
  16. #define boole_andc2 2
  17. #define boole_1 3
  18. #define boole_andc1 4
  19. #define boole_2 5
  20. #define boole_xor 6
  21. #define boole_ior 7
  22. #define boole_nor 8
  23. #define boole_eqv 9
  24. #define boole_c2 10
  25. #define boole_orc2 11
  26. #define boole_c1 12
  27. #define boole_orc1 13
  28. #define boole_nand 14
  29. #define boole_set 15
  30. /*
  31. * Bignums are represented as vectors of digits, where each digit
  32. * uses 31 bits, and all but the most significant digit are unsigned
  33. * (and thus do not use the 0x80000000L bit). The most significant
  34. * digit of a bignum is a signed 2-s complement value in 31 bits that
  35. * has been sign extended into the 0x80000000L bit, and thus its top
  36. * two bits (in the 32 bit word) will be either '00' or '11'.
  37. */
  38. #define top_bit_set(n) (((int32)(n)) < 0)
  39. #define top_bit(n) (((unsigned32)(n)) >> 31)
  40. #define set_top_bit(n) ((n) | (~0x7fffffff))
  41. #define clear_top_bit(n) ((n) & 0x7fffffff)
  42. #define signed_overflow(n) top_bit_set((n) ^ (((int32)(n))<<1))
  43. #ifdef MULDIV64
  44. /*
  45. * Here I do some arithmetic in-line. In the following macros I need to
  46. * take care that the names used for local variables do not clash with
  47. * those used in the body of the code. Hence the names r64 and c64, which
  48. * I must agree not to use elsewhere. Note also the "do {} while (0)" idiom
  49. * to avoid nasty problems with C syntax and the need for semicolons.
  50. */
  51. #define IMULTIPLY 1 /* External function not needed */
  52. #define Dmultiply(hi, lo, a, b, c) \
  53. do { unsigned64 r64 = (unsigned64)(a) * (unsigned64)(b) + \
  54. (unsigned32)(c); \
  55. (lo) = 0x7fffffffu & (unsigned32)r64; \
  56. (hi) = (unsigned32)(r64 >> 31); } while (0)
  57. #define IDIVIDE 1
  58. #define Ddivide(r, q, a, b, c) \
  59. do { unsigned64 r64 = (((unsigned64)(a)) << 31) | (unsigned64)(b); \
  60. unsigned64 c64 = (unsigned64)(unsigned32)(c); \
  61. q = (unsigned32)(r64 / c64); \
  62. r = (unsigned32)(r64 % c64); } while (0)
  63. #define Ddiv10_9(r, q, a, b) Ddivide(r, q, a, b, 1000000000u)
  64. #else
  65. #define Dmultiply(hi, lo, a, b, c) ((hi) = Imultiply(&(lo), (a), (b), (c)))
  66. #define Ddivide(r, q, a, b, c) ((r) = Idivide(&(q), (a), (b), (c)))
  67. #define Ddiv10_9(r, q, a, b) ((r) = Idiv10_9(&(q), (a), (b)))
  68. #endif
  69. #define fix_mask (-0x08000000)
  70. #define fixnum_minusp(a) ((int32)(a) < 0)
  71. #define bignum_minusp(a) ((int32)bignum_digits(a)[(bignum_length(a)>>2)-2]<0)
  72. extern Lisp_Object negateb(Lisp_Object);
  73. extern Lisp_Object copyb(Lisp_Object);
  74. extern Lisp_Object negate(Lisp_Object);
  75. extern Lisp_Object plus2(Lisp_Object a, Lisp_Object b);
  76. extern Lisp_Object difference2(Lisp_Object a, Lisp_Object b);
  77. extern Lisp_Object times2(Lisp_Object a, Lisp_Object b);
  78. extern Lisp_Object quot2(Lisp_Object a, Lisp_Object b);
  79. extern Lisp_Object CLquot2(Lisp_Object a, Lisp_Object b);
  80. extern Lisp_Object quotbn(Lisp_Object a, int32 n);
  81. extern Lisp_Object quotbn1(Lisp_Object a, int32 n);
  82. extern Lisp_Object quotbb(Lisp_Object a, Lisp_Object b);
  83. extern Lisp_Object Cremainder(Lisp_Object a, Lisp_Object b);
  84. extern Lisp_Object rembi(Lisp_Object a, Lisp_Object b);
  85. extern Lisp_Object rembb(Lisp_Object a, Lisp_Object b);
  86. extern Lisp_Object shrink_bignum(Lisp_Object a, int32 lena);
  87. extern Lisp_Object modulus(Lisp_Object a, Lisp_Object b);
  88. extern Lisp_Object rational(Lisp_Object a);
  89. extern Lisp_Object rationalize(Lisp_Object a);
  90. extern Lisp_Object lcm(Lisp_Object a, Lisp_Object b);
  91. extern Lisp_Object lengthen_by_one_bit(Lisp_Object a, int32 msd);
  92. extern CSLbool numeq2(Lisp_Object a, Lisp_Object b);
  93. extern CSLbool zerop(Lisp_Object a);
  94. extern CSLbool onep(Lisp_Object a);
  95. extern CSLbool minusp(Lisp_Object a);
  96. extern CSLbool plusp(Lisp_Object a);
  97. extern CSLbool lesspbd(Lisp_Object a, double b);
  98. extern CSLbool lessprd(Lisp_Object a, double b);
  99. extern CSLbool lesspdb(double a, Lisp_Object b);
  100. extern CSLbool lesspdr(double a, Lisp_Object b);
  101. extern Lisp_Object make_one_word_bignum(int32 n);
  102. extern Lisp_Object make_two_word_bignum(int32 a, unsigned32 b);
  103. extern Lisp_Object make_n_word_bignum(int32 a1, unsigned32 a2,
  104. unsigned32 a3, int32 n);
  105. extern Lisp_Object make_sfloat(double d);
  106. extern double float_of_integer(Lisp_Object a);
  107. extern Lisp_Object add1(Lisp_Object p);
  108. extern Lisp_Object sub1(Lisp_Object p);
  109. extern Lisp_Object integerp(Lisp_Object p);
  110. extern double float_of_number(Lisp_Object a);
  111. extern Lisp_Object make_boxfloat(double a, int32 type);
  112. extern Lisp_Object make_complex(Lisp_Object r, Lisp_Object i);
  113. extern Lisp_Object make_ratio(Lisp_Object p, Lisp_Object q);
  114. extern Lisp_Object ash(Lisp_Object a, Lisp_Object b);
  115. extern Lisp_Object lognot(Lisp_Object a);
  116. extern Lisp_Object logior2(Lisp_Object a, Lisp_Object b);
  117. extern Lisp_Object logxor2(Lisp_Object a, Lisp_Object b);
  118. extern Lisp_Object logand2(Lisp_Object a, Lisp_Object b);
  119. extern Lisp_Object logeqv2(Lisp_Object a, Lisp_Object b);
  120. extern Lisp_Object rationalf(double d);
  121. extern int _reduced_exp(double, double *);
  122. extern CSLbool lesspbi(Lisp_Object a, Lisp_Object b);
  123. extern CSLbool lesspib(Lisp_Object a, Lisp_Object b);
  124. #ifdef COMMON
  125. typedef struct Complex
  126. {
  127. double real;
  128. double imag;
  129. } Complex;
  130. extern Complex MS_CDECL Cln(Complex a);
  131. extern Complex MS_CDECL Ccos(Complex a);
  132. extern Complex MS_CDECL Cexp(Complex a);
  133. extern Complex MS_CDECL Cpow(Complex a, Complex b);
  134. extern double MS_CDECL Cabs(Complex a);
  135. #endif
  136. #endif /* header_arith_h */
  137. /* end of arith.h */