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.

307 lines
10 KiB

25 years ago
25 years ago
25 years ago
25 years ago
Extend the exponent range from 32 bits to 64 bits on selected platforms. * include/cln/number.h: Add signatures for operations with long long. * include/cln/complex_class.h: Likewise. * include/cln/real_class.h: Likewise. * include/cln/real.h: Likewise. * include/cln/rational_class.h: Likewise. * include/cln/rational.h: Likewise. * include/cln/integer_class.h: Likewise. * include/cln/integer.h: Likewise. * include/cln/float.h: Likewise. * include/cln/lfloat.h: Likewise. * include/cln/types.h (sintE and uintE): New types for exponents. * include/cln/*float.h: Use the new types for exponents. * include/cln/floatformat.h (float_format_t): Make underlying type compatible with sintE. * doc/cln.tex: Document changed float_exponent return value. * src/float/cl_F.h: Likewise. * src/float/ffloat/misc/cl_FF_exponent.cc: Likewise. * src/float/input/cl_F_read.cc: Likewise. * src/float/lfloat/cl_LF.h: Likewise. * src/float/lfloat/cl_LF_impl.h: Likewise. * src/float/lfloat/algebraic/cl_LF_sqrt.cc: Likewise. * src/float/lfloat/elem/cl_LF_1plus.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_compare.cc: Likewise. * src/float/lfloat/elem/cl_LF_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_from_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_fround.cc: Likewise. * src/float/lfloat/elem/cl_LF_ftrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_futrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_square.cc: Likewise. * src/float/lfloat/elem/cl_LF_to_I.cc: Likewise. * src/float/lfloat/misc/cl_LF_decode.cc: Likewise. * src/float/lfloat/misc/cl_LF_exponent.cc: Likewise. * src/float/lfloat/misc/cl_LF_idecode.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenrel.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenwith.cc: Likewise. * src/float/misc/cl_F_decode.cc: Likewise. * src/float/misc/cl_F_exponent.cc: Likewise. * src/float/misc/cl_F_shortenrel.cc: Likewise. * src/float/misc/cl_float_format.cc: Likewise. * src/float/output/cl_F_dprint.cc: Likewise. * src/float/sfloat/misc/cl_SF_exponent.cc: Likewise. * src/float/transcendental/cl_F_atanhx.cc: Likewise. * src/float/transcendental/cl_F_atanx.cc: Likewise. * src/float/transcendental/cl_F_cosh.cc: Likewise. * src/float/transcendental/cl_F_expx.cc: Likewise. * src/float/transcendental/cl_F_lnx.cc: Likewise. * src/float/transcendental/cl_F_sinhx.cc: Likewise. * src/float/transcendental/cl_F_sinx.cc: Likewise. * src/float/transcendental/cl_LF_pi.cc: Likewise. * src/integer/cl_I.h: Likewise. * src/complex/algebraic/cl_LF_hypot.cc: Likewise. * src/complex/elem/division/cl_C_LF_recip.cc: Likewise. * src/float/dfloat/misc/cl_DF_exponent.cc: Likewise. * src/integer/conv/cl_I_from_Q2.cc: Added. * src/base/cl_low.h (isqrtC): New function, for 64 bit falls back to... * src/base/low/cl_low_isqrt.cc (isqrt): ...this new implementation. * src/base/cl_macros.h (bitc): Make sure 64 bit is used if required by exponent operations. * examples/pi.cc: Support more than 646456614 decimal digits.
18 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
Extend the exponent range from 32 bits to 64 bits on selected platforms. * include/cln/number.h: Add signatures for operations with long long. * include/cln/complex_class.h: Likewise. * include/cln/real_class.h: Likewise. * include/cln/real.h: Likewise. * include/cln/rational_class.h: Likewise. * include/cln/rational.h: Likewise. * include/cln/integer_class.h: Likewise. * include/cln/integer.h: Likewise. * include/cln/float.h: Likewise. * include/cln/lfloat.h: Likewise. * include/cln/types.h (sintE and uintE): New types for exponents. * include/cln/*float.h: Use the new types for exponents. * include/cln/floatformat.h (float_format_t): Make underlying type compatible with sintE. * doc/cln.tex: Document changed float_exponent return value. * src/float/cl_F.h: Likewise. * src/float/ffloat/misc/cl_FF_exponent.cc: Likewise. * src/float/input/cl_F_read.cc: Likewise. * src/float/lfloat/cl_LF.h: Likewise. * src/float/lfloat/cl_LF_impl.h: Likewise. * src/float/lfloat/algebraic/cl_LF_sqrt.cc: Likewise. * src/float/lfloat/elem/cl_LF_1plus.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_compare.cc: Likewise. * src/float/lfloat/elem/cl_LF_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_from_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_fround.cc: Likewise. * src/float/lfloat/elem/cl_LF_ftrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_futrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_square.cc: Likewise. * src/float/lfloat/elem/cl_LF_to_I.cc: Likewise. * src/float/lfloat/misc/cl_LF_decode.cc: Likewise. * src/float/lfloat/misc/cl_LF_exponent.cc: Likewise. * src/float/lfloat/misc/cl_LF_idecode.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenrel.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenwith.cc: Likewise. * src/float/misc/cl_F_decode.cc: Likewise. * src/float/misc/cl_F_exponent.cc: Likewise. * src/float/misc/cl_F_shortenrel.cc: Likewise. * src/float/misc/cl_float_format.cc: Likewise. * src/float/output/cl_F_dprint.cc: Likewise. * src/float/sfloat/misc/cl_SF_exponent.cc: Likewise. * src/float/transcendental/cl_F_atanhx.cc: Likewise. * src/float/transcendental/cl_F_atanx.cc: Likewise. * src/float/transcendental/cl_F_cosh.cc: Likewise. * src/float/transcendental/cl_F_expx.cc: Likewise. * src/float/transcendental/cl_F_lnx.cc: Likewise. * src/float/transcendental/cl_F_sinhx.cc: Likewise. * src/float/transcendental/cl_F_sinx.cc: Likewise. * src/float/transcendental/cl_LF_pi.cc: Likewise. * src/integer/cl_I.h: Likewise. * src/complex/algebraic/cl_LF_hypot.cc: Likewise. * src/complex/elem/division/cl_C_LF_recip.cc: Likewise. * src/float/dfloat/misc/cl_DF_exponent.cc: Likewise. * src/integer/conv/cl_I_from_Q2.cc: Added. * src/base/cl_low.h (isqrtC): New function, for 64 bit falls back to... * src/base/low/cl_low_isqrt.cc (isqrt): ...this new implementation. * src/base/cl_macros.h (bitc): Make sure 64 bit is used if required by exponent operations. * examples/pi.cc: Support more than 646456614 decimal digits.
18 years ago
25 years ago
Extend the exponent range from 32 bits to 64 bits on selected platforms. * include/cln/number.h: Add signatures for operations with long long. * include/cln/complex_class.h: Likewise. * include/cln/real_class.h: Likewise. * include/cln/real.h: Likewise. * include/cln/rational_class.h: Likewise. * include/cln/rational.h: Likewise. * include/cln/integer_class.h: Likewise. * include/cln/integer.h: Likewise. * include/cln/float.h: Likewise. * include/cln/lfloat.h: Likewise. * include/cln/types.h (sintE and uintE): New types for exponents. * include/cln/*float.h: Use the new types for exponents. * include/cln/floatformat.h (float_format_t): Make underlying type compatible with sintE. * doc/cln.tex: Document changed float_exponent return value. * src/float/cl_F.h: Likewise. * src/float/ffloat/misc/cl_FF_exponent.cc: Likewise. * src/float/input/cl_F_read.cc: Likewise. * src/float/lfloat/cl_LF.h: Likewise. * src/float/lfloat/cl_LF_impl.h: Likewise. * src/float/lfloat/algebraic/cl_LF_sqrt.cc: Likewise. * src/float/lfloat/elem/cl_LF_1plus.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_compare.cc: Likewise. * src/float/lfloat/elem/cl_LF_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_from_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_fround.cc: Likewise. * src/float/lfloat/elem/cl_LF_ftrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_futrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_square.cc: Likewise. * src/float/lfloat/elem/cl_LF_to_I.cc: Likewise. * src/float/lfloat/misc/cl_LF_decode.cc: Likewise. * src/float/lfloat/misc/cl_LF_exponent.cc: Likewise. * src/float/lfloat/misc/cl_LF_idecode.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenrel.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenwith.cc: Likewise. * src/float/misc/cl_F_decode.cc: Likewise. * src/float/misc/cl_F_exponent.cc: Likewise. * src/float/misc/cl_F_shortenrel.cc: Likewise. * src/float/misc/cl_float_format.cc: Likewise. * src/float/output/cl_F_dprint.cc: Likewise. * src/float/sfloat/misc/cl_SF_exponent.cc: Likewise. * src/float/transcendental/cl_F_atanhx.cc: Likewise. * src/float/transcendental/cl_F_atanx.cc: Likewise. * src/float/transcendental/cl_F_cosh.cc: Likewise. * src/float/transcendental/cl_F_expx.cc: Likewise. * src/float/transcendental/cl_F_lnx.cc: Likewise. * src/float/transcendental/cl_F_sinhx.cc: Likewise. * src/float/transcendental/cl_F_sinx.cc: Likewise. * src/float/transcendental/cl_LF_pi.cc: Likewise. * src/integer/cl_I.h: Likewise. * src/complex/algebraic/cl_LF_hypot.cc: Likewise. * src/complex/elem/division/cl_C_LF_recip.cc: Likewise. * src/float/dfloat/misc/cl_DF_exponent.cc: Likewise. * src/integer/conv/cl_I_from_Q2.cc: Added. * src/base/cl_low.h (isqrtC): New function, for 64 bit falls back to... * src/base/low/cl_low_isqrt.cc (isqrt): ...this new implementation. * src/base/cl_macros.h (bitc): Make sure 64 bit is used if required by exponent operations. * examples/pi.cc: Support more than 646456614 decimal digits.
18 years ago
25 years ago
Extend the exponent range from 32 bits to 64 bits on selected platforms. * include/cln/number.h: Add signatures for operations with long long. * include/cln/complex_class.h: Likewise. * include/cln/real_class.h: Likewise. * include/cln/real.h: Likewise. * include/cln/rational_class.h: Likewise. * include/cln/rational.h: Likewise. * include/cln/integer_class.h: Likewise. * include/cln/integer.h: Likewise. * include/cln/float.h: Likewise. * include/cln/lfloat.h: Likewise. * include/cln/types.h (sintE and uintE): New types for exponents. * include/cln/*float.h: Use the new types for exponents. * include/cln/floatformat.h (float_format_t): Make underlying type compatible with sintE. * doc/cln.tex: Document changed float_exponent return value. * src/float/cl_F.h: Likewise. * src/float/ffloat/misc/cl_FF_exponent.cc: Likewise. * src/float/input/cl_F_read.cc: Likewise. * src/float/lfloat/cl_LF.h: Likewise. * src/float/lfloat/cl_LF_impl.h: Likewise. * src/float/lfloat/algebraic/cl_LF_sqrt.cc: Likewise. * src/float/lfloat/elem/cl_LF_1plus.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_I_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_compare.cc: Likewise. * src/float/lfloat/elem/cl_LF_div.cc: Likewise. * src/float/lfloat/elem/cl_LF_from_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_fround.cc: Likewise. * src/float/lfloat/elem/cl_LF_ftrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_futrunc.cc: Likewise. * src/float/lfloat/elem/cl_LF_mul.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale.cc: Likewise. * src/float/lfloat/elem/cl_LF_scale_I.cc: Likewise. * src/float/lfloat/elem/cl_LF_square.cc: Likewise. * src/float/lfloat/elem/cl_LF_to_I.cc: Likewise. * src/float/lfloat/misc/cl_LF_decode.cc: Likewise. * src/float/lfloat/misc/cl_LF_exponent.cc: Likewise. * src/float/lfloat/misc/cl_LF_idecode.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenrel.cc: Likewise. * src/float/lfloat/misc/cl_LF_shortenwith.cc: Likewise. * src/float/misc/cl_F_decode.cc: Likewise. * src/float/misc/cl_F_exponent.cc: Likewise. * src/float/misc/cl_F_shortenrel.cc: Likewise. * src/float/misc/cl_float_format.cc: Likewise. * src/float/output/cl_F_dprint.cc: Likewise. * src/float/sfloat/misc/cl_SF_exponent.cc: Likewise. * src/float/transcendental/cl_F_atanhx.cc: Likewise. * src/float/transcendental/cl_F_atanx.cc: Likewise. * src/float/transcendental/cl_F_cosh.cc: Likewise. * src/float/transcendental/cl_F_expx.cc: Likewise. * src/float/transcendental/cl_F_lnx.cc: Likewise. * src/float/transcendental/cl_F_sinhx.cc: Likewise. * src/float/transcendental/cl_F_sinx.cc: Likewise. * src/float/transcendental/cl_LF_pi.cc: Likewise. * src/integer/cl_I.h: Likewise. * src/complex/algebraic/cl_LF_hypot.cc: Likewise. * src/complex/elem/division/cl_C_LF_recip.cc: Likewise. * src/float/dfloat/misc/cl_DF_exponent.cc: Likewise. * src/integer/conv/cl_I_from_Q2.cc: Added. * src/base/cl_low.h (isqrtC): New function, for 64 bit falls back to... * src/base/low/cl_low_isqrt.cc (isqrt): ...this new implementation. * src/base/cl_macros.h (bitc): Make sure 64 bit is used if required by exponent operations. * examples/pi.cc: Support more than 646456614 decimal digits.
18 years ago
25 years ago
25 years ago
25 years ago
  1. // Basic definitions of numbers
  2. #ifndef _CL_NUMBER_H
  3. #define _CL_NUMBER_H
  4. #include "cln/object.h"
  5. #include "cln/malloc.h"
  6. // Type hierachy:
  7. // Number (N) =
  8. // Real (R) =
  9. // Float (F) =
  10. // Short float (SF)
  11. // Single float (FF)
  12. // Double float (DF)
  13. // Long float (LF)
  14. // Rational (RA) =
  15. // Integer (I) =
  16. // Fixnum (FN)
  17. // Bignum (BN)
  18. // Ratio (RT)
  19. // Complex (C)
  20. // Constructors and assignment operators from C numeric types.
  21. #ifdef _MSC_VER
  22. // Workaround to force MSVC to tag the symbol with the cln:: namespace
  23. // When declaring inside an inlined function the symbol is placed in the
  24. // global namespace!
  25. namespace cln {
  26. extern cl_private_thing cl_I_constructor_from_L (sint32 wert);
  27. extern cl_private_thing cl_I_constructor_from_UL (uint32 wert);
  28. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert);
  29. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert);
  30. }
  31. #endif
  32. #define CL_DEFINE_INT_CONSTRUCTOR(_class_,_type_) \
  33. inline _class_::_class_ (const _type_ wert) \
  34. { \
  35. word = cl_combine(cl_FN_tag,wert); \
  36. }
  37. #define CL_DEFINE_INT_CONSTRUCTORS(_class_) \
  38. CL_DEFINE_INT_CONSTRUCTOR(_class_, int) \
  39. CL_DEFINE_INT_CONSTRUCTOR(_class_, unsigned int)
  40. #define CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_,_type_) \
  41. inline _class_& _class_::operator= (const _type_ wert) \
  42. { \
  43. cl_dec_refcount(*this); \
  44. word = cl_combine(cl_FN_tag,wert); \
  45. return *this; \
  46. }
  47. #define CL_DEFINE_INT_ASSIGNMENT_OPERATORS(_class_) \
  48. CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_, int) \
  49. CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_, unsigned int)
  50. #if (long_bitsize==32)
  51. // `long' == `sintL', `unsigned long' == `uintL'.
  52. #define CL_DEFINE_LONG_CONSTRUCTORS(_class_) \
  53. inline _class_::_class_ (const long wert) \
  54. { \
  55. extern cl_private_thing cl_I_constructor_from_L (sint32 wert); \
  56. pointer = cl_I_constructor_from_L(wert); \
  57. } \
  58. inline _class_::_class_ (const unsigned long wert) \
  59. { \
  60. extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); \
  61. pointer = cl_I_constructor_from_UL(wert); \
  62. }
  63. #elif (long_bitsize==64)
  64. // `long' == `sintQ', `unsigned long' == `uintQ'.
  65. #define CL_DEFINE_LONG_CONSTRUCTORS(_class_) \
  66. inline _class_::_class_ (const long wert) \
  67. { \
  68. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  69. pointer = cl_I_constructor_from_Q(wert); \
  70. } \
  71. inline _class_::_class_ (const unsigned long wert) \
  72. { \
  73. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  74. pointer = cl_I_constructor_from_UQ(wert); \
  75. }
  76. #endif
  77. #if (long_bitsize==32)
  78. // `long' == `sintL', `unsigned long' == `uintL'.
  79. #define CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(_class_) \
  80. inline _class_& _class_::operator= (const long wert) \
  81. { \
  82. extern cl_private_thing cl_I_constructor_from_L (sint32 wert); \
  83. cl_dec_refcount(*this); \
  84. pointer = cl_I_constructor_from_L(wert); \
  85. return *this; \
  86. } \
  87. inline _class_& _class_::operator= (const unsigned long wert) \
  88. { \
  89. extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); \
  90. cl_dec_refcount(*this); \
  91. pointer = cl_I_constructor_from_UL(wert); \
  92. return *this; \
  93. }
  94. #elif (long_bitsize==64)
  95. // `long' == `sintQ', `unsigned long' == `uintQ'.
  96. #define CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(_class_) \
  97. inline _class_& _class_::operator= (const long wert) \
  98. { \
  99. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  100. cl_dec_refcount(*this); \
  101. pointer = cl_I_constructor_from_Q(wert); \
  102. return *this; \
  103. } \
  104. inline _class_& _class_::operator= (const unsigned long wert) \
  105. { \
  106. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  107. cl_dec_refcount(*this); \
  108. pointer = cl_I_constructor_from_UQ(wert); \
  109. return *this; \
  110. }
  111. #endif
  112. #ifdef HAVE_LONGLONG
  113. #if (long_long_bitsize==64)
  114. // `long' == `sintQ', `unsigned long' == `uintQ'.
  115. #define CL_DEFINE_LONGLONG_CONSTRUCTORS(_class_) \
  116. inline _class_::_class_ (const long long wert) \
  117. { \
  118. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  119. pointer = cl_I_constructor_from_Q(wert); \
  120. } \
  121. inline _class_::_class_ (const unsigned long long wert) \
  122. { \
  123. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  124. pointer = cl_I_constructor_from_UQ(wert); \
  125. }
  126. #define CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(_class_) \
  127. inline _class_& _class_::operator= (const long long wert) \
  128. { \
  129. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  130. cl_dec_refcount(*this); \
  131. pointer = cl_I_constructor_from_Q(wert); \
  132. return *this; \
  133. } \
  134. inline _class_& _class_::operator= (const unsigned long long wert) \
  135. { \
  136. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  137. cl_dec_refcount(*this); \
  138. pointer = cl_I_constructor_from_UQ(wert); \
  139. return *this; \
  140. }
  141. #endif
  142. #endif
  143. namespace cln {
  144. // Constructors and assignment operators from C numeric types.
  145. // from `float':
  146. extern cl_private_thing cl_float_to_FF_pointer (const float val);
  147. #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \
  148. inline _class_ :: _class_ (const float x) \
  149. { \
  150. pointer = cl_float_to_FF_pointer(x); \
  151. } \
  152. inline _class_& _class_::operator= (const float x) \
  153. { \
  154. cl_dec_refcount(*this); \
  155. pointer = cl_float_to_FF_pointer(x); \
  156. return *this; \
  157. }
  158. // from `double':
  159. extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const double val);
  160. #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \
  161. inline _class_::_class_ (const double x) \
  162. { \
  163. pointer = cl_double_to_DF_pointer(x); \
  164. } \
  165. inline _class_& _class_::operator= (const double x) \
  166. { \
  167. cl_dec_refcount(*this); \
  168. pointer = cl_double_to_DF_pointer(x); \
  169. return *this; \
  170. }
  171. // Abstract class of all numbers.
  172. class cl_number : public cl_gcobject {
  173. public:
  174. // Default constructor. (Used for objects with no initializer.)
  175. cl_number ();
  176. // Copy constructor. (Used for function argument passing and function
  177. // return value, and of course for objects with initializers of the same type.)
  178. cl_number (const cl_number& x);
  179. // Converters. (Used for function argument passing and function return values.)
  180. // Assignment operators. (Used for assignments.)
  181. cl_number& operator= (const cl_number&);
  182. // Constructors and assignment operators from C numeric types.
  183. cl_number (const int); // |argument| must be < 2^29
  184. cl_number (const unsigned int); // argument must be < 2^29
  185. cl_number (const long);
  186. cl_number (const unsigned long);
  187. #ifdef HAVE_LONGLONG
  188. cl_number (const long long);
  189. cl_number (const unsigned long long);
  190. #endif
  191. cl_number (const float);
  192. cl_number (const double);
  193. cl_number& operator= (const int); // |argument| must be < 2^29
  194. cl_number& operator= (const unsigned int); // argument must be < 2^29
  195. cl_number& operator= (const long);
  196. cl_number& operator= (const unsigned long);
  197. cl_number& operator= (const float);
  198. cl_number& operator= (const double);
  199. #ifdef HAVE_LONGLONG
  200. cl_number& operator= (const long long);
  201. cl_number& operator= (const unsigned long long);
  202. #endif
  203. // Other constructors.
  204. // cl_number (const char *);
  205. // Private pointer manipulations.
  206. cl_number (cl_private_thing);
  207. };
  208. // Private constructors.
  209. inline cl_number::cl_number (cl_private_thing ptr) : cl_gcobject (ptr) {}
  210. // The assignment operators:
  211. CL_DEFINE_ASSIGNMENT_OPERATOR(cl_number, cl_number)
  212. // The default constructors.
  213. inline cl_number::cl_number ()
  214. : cl_gcobject ((cl_private_thing) cl_combine(cl_FN_tag,0)) {}
  215. // The copy constructors.
  216. CL_DEFINE_COPY_CONSTRUCTOR2(cl_number,cl_gcobject)
  217. // Constructors and assignment operators from C numeric types.
  218. CL_DEFINE_INT_CONSTRUCTORS(cl_number)
  219. CL_DEFINE_INT_ASSIGNMENT_OPERATORS(cl_number)
  220. CL_DEFINE_LONG_CONSTRUCTORS(cl_number)
  221. CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(cl_number)
  222. #ifdef HAVE_LONGLONG
  223. CL_DEFINE_LONGLONG_CONSTRUCTORS(cl_number)
  224. CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(cl_number)
  225. #endif
  226. CL_DEFINE_FLOAT_CONSTRUCTOR(cl_number)
  227. CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number)
  228. // Hack section.
  229. // Conversions to subtypes without checking, template version:
  230. // the<cl_I>(x) converts x to a cl_I, without change of representation.
  231. template<class type>
  232. inline const type& the(const cl_number& x)
  233. {
  234. // check that sizeof(type)==sizeof(cl_number)
  235. typedef int assertion1 [1 - 2 * (sizeof(type) != sizeof(cl_number))];
  236. return *(const type *) &x;
  237. }
  238. // Conversions to subtypes without checking, macro version:
  239. // The(cl_I)(x) converts x to a cl_I, without change of representation.
  240. #define The(type) *(const type *) & cl_identity
  241. // This inline function is for type checking purposes only.
  242. inline const cl_number& cl_identity (const cl_number& x) { return x; }
  243. } // namespace cln
  244. // Conversions to subtypes:
  245. // As(cl_I)(x) returns x as a cl_I. It first checks that x is a cl_I
  246. // and then returns it without change of representation.
  247. #if 0 // no debug information
  248. #define As(type) type##_As
  249. #define CL_DEFINE_AS_CONVERSION(_class_) \
  250. extern const _class_& _class_##_As (const cl_number& x); \
  251. inline const _class_& _class_##_As (const _class_& x) { return x; }
  252. #else // Line number information for ease of debugging.
  253. #define As(type) type##_As cl_as_aux
  254. #define cl_as_aux(expr) (expr,__FILE__,__LINE__)
  255. #define CL_DEFINE_AS_CONVERSION(_class_) \
  256. extern const _class_& _class_##_As (const cl_number& x, const char * filename, int line); \
  257. inline const _class_& _class_##_As (const _class_& x, const char * filename, int line) { (void)filename; (void)line; return x; }
  258. #endif
  259. // Mutable(type,x);
  260. // x should be a variable `const type x' or `const type& x'.
  261. // This macro introduces a new variable `type& x' whose value can be
  262. // modified. Useful for modifying the argument of a function which takes
  263. // a `const type &x'.
  264. // Warning: To apply this to a function's formal parameter, a block { ... }
  265. // must be inserted.
  266. #define Mutable(type,x) \
  267. type __copied_##x = x; \
  268. type& x = __copied_##x;
  269. // DeclareType(type,x);
  270. // x should be a variable of some subtype of `cl_number'. type should be
  271. // a subtype of `cl_number'. A new variable of the given type is declared,
  272. // with name x and which refers to x (by reference, with const attribute).
  273. #define DeclareType(type,x) \
  274. const type& __tmp_##x = *(const type*) &x; \
  275. const type& x = __tmp_##x;
  276. #endif /* _CL_NUMBER_H */