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.

295 lines
9.9 KiB

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. #define CL_DEFINE_INT_CONSTRUCTOR(_class_,_type_) \
  22. inline _class_::_class_ (const _type_ wert) \
  23. { \
  24. word = cl_combine(cl_FN_tag,wert); \
  25. }
  26. #define CL_DEFINE_INT_CONSTRUCTORS(_class_) \
  27. CL_DEFINE_INT_CONSTRUCTOR(_class_, int) \
  28. CL_DEFINE_INT_CONSTRUCTOR(_class_, unsigned int)
  29. #define CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_,_type_) \
  30. inline _class_& _class_::operator= (const _type_ wert) \
  31. { \
  32. cl_dec_refcount(*this); \
  33. word = cl_combine(cl_FN_tag,wert); \
  34. return *this; \
  35. }
  36. #define CL_DEFINE_INT_ASSIGNMENT_OPERATORS(_class_) \
  37. CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_, int) \
  38. CL_DEFINE_INT_ASSIGNMENT_OPERATOR(_class_, unsigned int)
  39. #if (long_bitsize==32)
  40. // `long' == `sintL', `unsigned long' == `uintL'.
  41. #define CL_DEFINE_LONG_CONSTRUCTORS(_class_) \
  42. inline _class_::_class_ (const long wert) \
  43. { \
  44. extern cl_private_thing cl_I_constructor_from_L (sint32 wert); \
  45. pointer = cl_I_constructor_from_L(wert); \
  46. } \
  47. inline _class_::_class_ (const unsigned long wert) \
  48. { \
  49. extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); \
  50. pointer = cl_I_constructor_from_UL(wert); \
  51. }
  52. #elif (long_bitsize==64)
  53. // `long' == `sintQ', `unsigned long' == `uintQ'.
  54. #define CL_DEFINE_LONG_CONSTRUCTORS(_class_) \
  55. inline _class_::_class_ (const long wert) \
  56. { \
  57. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  58. pointer = cl_I_constructor_from_Q(wert); \
  59. } \
  60. inline _class_::_class_ (const unsigned long wert) \
  61. { \
  62. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  63. pointer = cl_I_constructor_from_UQ(wert); \
  64. }
  65. #endif
  66. #if (long_bitsize==32)
  67. // `long' == `sintL', `unsigned long' == `uintL'.
  68. #define CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(_class_) \
  69. inline _class_& _class_::operator= (const long wert) \
  70. { \
  71. extern cl_private_thing cl_I_constructor_from_L (sint32 wert); \
  72. cl_dec_refcount(*this); \
  73. pointer = cl_I_constructor_from_L(wert); \
  74. return *this; \
  75. } \
  76. inline _class_& _class_::operator= (const unsigned long wert) \
  77. { \
  78. extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); \
  79. cl_dec_refcount(*this); \
  80. pointer = cl_I_constructor_from_UL(wert); \
  81. return *this; \
  82. }
  83. #elif (long_bitsize==64)
  84. // `long' == `sintQ', `unsigned long' == `uintQ'.
  85. #define CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(_class_) \
  86. inline _class_& _class_::operator= (const long wert) \
  87. { \
  88. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  89. cl_dec_refcount(*this); \
  90. pointer = cl_I_constructor_from_Q(wert); \
  91. return *this; \
  92. } \
  93. inline _class_& _class_::operator= (const unsigned long wert) \
  94. { \
  95. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  96. cl_dec_refcount(*this); \
  97. pointer = cl_I_constructor_from_UQ(wert); \
  98. return *this; \
  99. }
  100. #endif
  101. #ifdef HAVE_LONGLONG
  102. #if (long_long_bitsize==64)
  103. // `long' == `sintQ', `unsigned long' == `uintQ'.
  104. #define CL_DEFINE_LONGLONG_CONSTRUCTORS(_class_) \
  105. inline _class_::_class_ (const long long wert) \
  106. { \
  107. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  108. pointer = cl_I_constructor_from_Q(wert); \
  109. } \
  110. inline _class_::_class_ (const unsigned long long wert) \
  111. { \
  112. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  113. pointer = cl_I_constructor_from_UQ(wert); \
  114. }
  115. #define CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(_class_) \
  116. inline _class_& _class_::operator= (const long long wert) \
  117. { \
  118. extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \
  119. cl_dec_refcount(*this); \
  120. pointer = cl_I_constructor_from_Q(wert); \
  121. return *this; \
  122. } \
  123. inline _class_& _class_::operator= (const unsigned long long wert) \
  124. { \
  125. extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \
  126. cl_dec_refcount(*this); \
  127. pointer = cl_I_constructor_from_UQ(wert); \
  128. return *this; \
  129. }
  130. #endif
  131. #endif
  132. namespace cln {
  133. // Constructors and assignment operators from C numeric types.
  134. // from `float':
  135. extern cl_private_thing cl_float_to_FF_pointer (const float val);
  136. #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \
  137. inline _class_ :: _class_ (const float x) \
  138. { \
  139. pointer = cl_float_to_FF_pointer(x); \
  140. } \
  141. inline _class_& _class_::operator= (const float x) \
  142. { \
  143. cl_dec_refcount(*this); \
  144. pointer = cl_float_to_FF_pointer(x); \
  145. return *this; \
  146. }
  147. // from `double':
  148. extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const double val);
  149. #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \
  150. inline _class_::_class_ (const double x) \
  151. { \
  152. pointer = cl_double_to_DF_pointer(x); \
  153. } \
  154. inline _class_& _class_::operator= (const double x) \
  155. { \
  156. cl_dec_refcount(*this); \
  157. pointer = cl_double_to_DF_pointer(x); \
  158. return *this; \
  159. }
  160. // Abstract class of all numbers.
  161. class cl_number : public cl_gcobject {
  162. public:
  163. // Default constructor. (Used for objects with no initializer.)
  164. cl_number ();
  165. // Copy constructor. (Used for function argument passing and function
  166. // return value, and of course for objects with initializers of the same type.)
  167. cl_number (const cl_number& x);
  168. // Converters. (Used for function argument passing and function return values.)
  169. // Assignment operators. (Used for assignments.)
  170. cl_number& operator= (const cl_number&);
  171. // Constructors and assignment operators from C numeric types.
  172. cl_number (const int); // |argument| must be < 2^29
  173. cl_number (const unsigned int); // argument must be < 2^29
  174. cl_number (const long);
  175. cl_number (const unsigned long);
  176. #ifdef HAVE_LONGLONG
  177. cl_number (const long long);
  178. cl_number (const unsigned long long);
  179. #endif
  180. cl_number (const float);
  181. cl_number (const double);
  182. cl_number& operator= (const int); // |argument| must be < 2^29
  183. cl_number& operator= (const unsigned int); // argument must be < 2^29
  184. cl_number& operator= (const long);
  185. cl_number& operator= (const unsigned long);
  186. cl_number& operator= (const float);
  187. cl_number& operator= (const double);
  188. #ifdef HAVE_LONGLONG
  189. cl_number& operator= (const long long);
  190. cl_number& operator= (const unsigned long long);
  191. #endif
  192. // Other constructors.
  193. // cl_number (const char *);
  194. // Private pointer manipulations.
  195. cl_number (cl_private_thing);
  196. };
  197. // Private constructors.
  198. inline cl_number::cl_number (cl_private_thing ptr) : cl_gcobject (ptr) {}
  199. // The assignment operators:
  200. CL_DEFINE_ASSIGNMENT_OPERATOR(cl_number, cl_number)
  201. // The default constructors.
  202. inline cl_number::cl_number ()
  203. : cl_gcobject ((cl_private_thing) cl_combine(cl_FN_tag,0)) {}
  204. // The copy constructors.
  205. CL_DEFINE_COPY_CONSTRUCTOR2(cl_number,cl_gcobject)
  206. // Constructors and assignment operators from C numeric types.
  207. CL_DEFINE_INT_CONSTRUCTORS(cl_number)
  208. CL_DEFINE_INT_ASSIGNMENT_OPERATORS(cl_number)
  209. CL_DEFINE_LONG_CONSTRUCTORS(cl_number)
  210. CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(cl_number)
  211. #ifdef HAVE_LONGLONG
  212. CL_DEFINE_LONGLONG_CONSTRUCTORS(cl_number)
  213. CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(cl_number)
  214. #endif
  215. CL_DEFINE_FLOAT_CONSTRUCTOR(cl_number)
  216. CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number)
  217. // Hack section.
  218. // Conversions to subtypes without checking, template version:
  219. // the<cl_I>(x) converts x to a cl_I, without change of representation.
  220. template<class type>
  221. inline const type& the(const cl_number& x)
  222. {
  223. // check that sizeof(type)==sizeof(cl_number)
  224. typedef int assertion1 [1 - 2 * (sizeof(type) != sizeof(cl_number))];
  225. return *(const type *) &x;
  226. }
  227. // Conversions to subtypes without checking, macro version:
  228. // The(cl_I)(x) converts x to a cl_I, without change of representation.
  229. #define The(type) *(const type *) & cl_identity
  230. // This inline function is for type checking purposes only.
  231. inline const cl_number& cl_identity (const cl_number& x) { return x; }
  232. } // namespace cln
  233. // Conversions to subtypes:
  234. // As(cl_I)(x) returns x as a cl_I. It first checks that x is a cl_I
  235. // and then returns it without change of representation.
  236. #if 0 // no debug information
  237. #define As(type) type##_As
  238. #define CL_DEFINE_AS_CONVERSION(_class_) \
  239. extern const _class_& _class_##_As (const cl_number& x); \
  240. inline const _class_& _class_##_As (const _class_& x) { return x; }
  241. #else // Line number information for ease of debugging.
  242. #define As(type) type##_As cl_as_aux
  243. #define cl_as_aux(expr) (expr,__FILE__,__LINE__)
  244. #define CL_DEFINE_AS_CONVERSION(_class_) \
  245. extern const _class_& _class_##_As (const cl_number& x, const char * filename, int line); \
  246. inline const _class_& _class_##_As (const _class_& x, const char * filename, int line) { (void)filename; (void)line; return x; }
  247. #endif
  248. // Mutable(type,x);
  249. // x should be a variable `const type x' or `const type& x'.
  250. // This macro introduces a new variable `type& x' whose value can be
  251. // modified. Useful for modifying the argument of a function which takes
  252. // a `const type &x'.
  253. // Warning: To apply this to a function's formal parameter, a block { ... }
  254. // must be inserted.
  255. #define Mutable(type,x) \
  256. type __copied_##x = x; \
  257. type& x = __copied_##x;
  258. // DeclareType(type,x);
  259. // x should be a variable of some subtype of `cl_number'. type should be
  260. // a subtype of `cl_number'. A new variable of the given type is declared,
  261. // with name x and which refers to x (by reference, with const attribute).
  262. #define DeclareType(type,x) \
  263. const type& __tmp_##x = *(const type*) &x; \
  264. const type& x = __tmp_##x;
  265. #endif /* _CL_NUMBER_H */