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.

193 lines
5.1 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. // cl_C internals
  2. #ifndef _CL_C_H
  3. #define _CL_C_H
  4. #include "cln/number.h"
  5. #include "cln/complex.h"
  6. #include "cln/sfloat_class.h"
  7. #include "cln/ffloat_class.h"
  8. #include "cln/dfloat_class.h"
  9. #include "cln/lfloat_class.h"
  10. #include "cl_macros.h"
  11. #include "cln/malloc.h"
  12. namespace cln {
  13. struct cl_heap_complex : cl_heap {
  14. cl_R realpart;
  15. cl_R imagpart;
  16. };
  17. inline cl_heap_complex* TheComplex (cl_heap_complex* p)
  18. { return p; }
  19. inline cl_heap_complex* TheComplex (const cl_number& obj)
  20. { return (cl_heap_complex*)(obj.pointer); }
  21. inline cl_heap_complex* allocate_complex (const cl_R& real, const cl_R& imag)
  22. {
  23. cl_heap_complex* p = (cl_heap_complex*) malloc_hook(sizeof(cl_heap_complex));
  24. p->refcount = 1;
  25. p->type = &cl_class_complex;
  26. p->realpart.pointer = real.pointer; cl_inc_refcount(real);
  27. p->imagpart.pointer = imag.pointer; cl_inc_refcount(imag);
  28. return p;
  29. }
  30. // Private constructor.
  31. // ptr should be the result of some allocate_complex() call.
  32. inline cl_N::cl_N (cl_heap_complex* ptr)
  33. : cl_number ((cl_private_thing) ptr) {}
  34. // Both work, but the first definition results in less compiler-generated
  35. // temporaries.
  36. #if 1
  37. #define Complex cl_heap_complex*
  38. #else
  39. #define Complex cl_N
  40. #endif
  41. // Type tests
  42. inline cl_boolean realp (const cl_N& x)
  43. {
  44. if (x.pointer_p())
  45. if (x.heappointer->type == &cl_class_complex)
  46. return cl_false;
  47. return cl_true;
  48. }
  49. inline cl_boolean complexp (const cl_N& x)
  50. {
  51. if (x.pointer_p())
  52. if (x.heappointer->type == &cl_class_complex)
  53. return cl_true;
  54. return cl_false;
  55. }
  56. // Comparison with a fixnum.
  57. inline cl_boolean eq (const cl_N& x, sint32 y)
  58. {
  59. return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
  60. }
  61. inline cl_boolean exact_zerop (const cl_N& x)
  62. {
  63. return eq(x,0);
  64. }
  65. // A complex (cl_C) is a number which is not a real number (cl_R).
  66. // typedef
  67. class cl_C : public cl_N {
  68. public:
  69. };
  70. inline cl_boolean realp (const cl_C& x)
  71. { unused x; return cl_false; }
  72. inline cl_boolean complexp (const cl_C& x)
  73. { unused x; return cl_true; }
  74. // Liefert zu reellen Zahlen a und b /= Fixnum 0 die komplexe Zahl a+bi.
  75. // complex_C(a,b)
  76. extern const cl_N complex_C (const cl_R& a, const cl_R& b);
  77. // realpart(x) liefert den Realteil der Zahl x.
  78. // imagpart(x) liefert den Imagin�rteil der Zahl x.
  79. inline const cl_R& realpart (const cl_C& x)
  80. {
  81. return TheComplex(x)->realpart;
  82. }
  83. inline const cl_R& imagpart (const cl_C& x)
  84. {
  85. return TheComplex(x)->imagpart;
  86. }
  87. // Primitive forms of complex numbers with restricted part type.
  88. // typedef
  89. struct cl_C_SF {
  90. cl_SF realpart;
  91. cl_SF imagpart;
  92. cl_C_SF (const cl_SF& re, const cl_SF& im) : realpart(re), imagpart(im) {}
  93. };
  94. inline const cl_N complex_C (const cl_C_SF& c)
  95. { return complex_C(c.realpart,c.imagpart); }
  96. // typedef
  97. struct cl_C_FF {
  98. cl_FF realpart;
  99. cl_FF imagpart;
  100. cl_C_FF (const cl_FF& re, const cl_FF& im) : realpart(re), imagpart(im) {}
  101. };
  102. inline const cl_N complex_C (const cl_C_FF& c)
  103. { return complex_C(c.realpart,c.imagpart); }
  104. // typedef
  105. struct cl_C_DF {
  106. cl_DF realpart;
  107. cl_DF imagpart;
  108. cl_C_DF (const cl_DF& re, const cl_DF& im) : realpart(re), imagpart(im) {}
  109. };
  110. inline const cl_N complex_C (const cl_C_DF& c)
  111. { return complex_C(c.realpart,c.imagpart); }
  112. // typedef
  113. struct cl_C_LF {
  114. cl_LF realpart;
  115. cl_LF imagpart;
  116. cl_C_LF (const cl_LF& re, const cl_LF& im) : realpart(re), imagpart(im) {}
  117. };
  118. inline const cl_N complex_C (const cl_C_LF& c)
  119. { return complex_C(c.realpart,c.imagpart); }
  120. // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Short-Floats sind.
  121. extern const cl_C_SF cl_C_recip (const cl_SF& a, const cl_SF& b);
  122. // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Single-Floats sind.
  123. extern const cl_C_FF cl_C_recip (const cl_FF& a, const cl_FF& b);
  124. // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b Double-Floats sind.
  125. extern const cl_C_DF cl_C_recip (const cl_DF& a, const cl_DF& b);
  126. // cl_C_recip(a,b) liefert 1/(a+bi), wo a und b gleichlange Long-Floats sind.
  127. extern const cl_C_LF cl_C_recip (const cl_LF& a, const cl_LF& b);
  128. // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Short-Floats sind.
  129. extern const cl_SF cl_hypot (const cl_SF& a, const cl_SF& b);
  130. // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Single-Floats sind.
  131. extern const cl_FF cl_hypot (const cl_FF& a, const cl_FF& b);
  132. // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b Double-Floats sind.
  133. extern const cl_DF cl_hypot (const cl_DF& a, const cl_DF& b);
  134. // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b gleichlange Long-Floats sind.
  135. extern const cl_LF cl_hypot (const cl_LF& a, const cl_LF& b);
  136. // cl_C_hypot(a,b) liefert abs(a+bi), wo a und b reelle Zahlen sind.
  137. extern const cl_R cl_hypot (const cl_R& a, const cl_R& b);
  138. // Liefert (abs x), wo x eine nicht-reelle Zahl ist.
  139. extern const cl_R abs (const cl_C& x);
  140. // typedef
  141. struct cl_C_R {
  142. cl_R realpart;
  143. cl_R imagpart;
  144. cl_C_R () : realpart(0), imagpart(0) {}
  145. cl_C_R (const cl_R& re, const cl_R& im) : realpart(re), imagpart(im) {}
  146. };
  147. // Hilfsfunktion f�r atanh und atan: u+iv := artanh(x+iy). Liefert cl_C_R(u,v).
  148. extern const cl_C_R atanh (const cl_R& x, const cl_R& y);
  149. // Hilfsfunktion f�r asinh und asin: u+iv := arsinh(x+iy). Liefert cl_C_R(u,v).
  150. extern const cl_C_R asinh (const cl_R& x, const cl_R& y);
  151. } // namespace cln
  152. #endif /* _CL_C_H */