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.

297 lines
10 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
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. union ffloatjanus;
  136. extern cl_private_thing cl_float_to_FF_pointer (const union ffloatjanus& val);
  137. #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \
  138. inline _class_ :: _class_ (const float x) \
  139. { \
  140. pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \
  141. } \
  142. inline _class_& _class_::operator= (const float x) \
  143. { \
  144. cl_dec_refcount(*this); \
  145. pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \
  146. return *this; \
  147. }
  148. // from `double':
  149. union dfloatjanus;
  150. extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const union dfloatjanus& val);
  151. #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \
  152. inline _class_::_class_ (const double x) \
  153. { \
  154. pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \
  155. } \
  156. inline _class_& _class_::operator= (const double x) \
  157. { \
  158. cl_dec_refcount(*this); \
  159. pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \
  160. return *this; \
  161. }
  162. // Abstract class of all numbers.
  163. class cl_number : public cl_gcobject {
  164. public:
  165. // Default constructor. (Used for objects with no initializer.)
  166. cl_number ();
  167. // Copy constructor. (Used for function argument passing and function
  168. // return value, and of course for objects with initializers of the same type.)
  169. cl_number (const cl_number& x);
  170. // Converters. (Used for function argument passing and function return values.)
  171. // Assignment operators. (Used for assignments.)
  172. cl_number& operator= (const cl_number&);
  173. // Constructors and assignment operators from C numeric types.
  174. cl_number (const int); // |argument| must be < 2^29
  175. cl_number (const unsigned int); // argument must be < 2^29
  176. cl_number (const long);
  177. cl_number (const unsigned long);
  178. #ifdef HAVE_LONGLONG
  179. cl_number (const long long);
  180. cl_number (const unsigned long long);
  181. #endif
  182. cl_number (const float);
  183. cl_number (const double);
  184. cl_number& operator= (const int); // |argument| must be < 2^29
  185. cl_number& operator= (const unsigned int); // argument must be < 2^29
  186. cl_number& operator= (const long);
  187. cl_number& operator= (const unsigned long);
  188. cl_number& operator= (const float);
  189. cl_number& operator= (const double);
  190. #ifdef HAVE_LONGLONG
  191. cl_number& operator= (const long long);
  192. cl_number& operator= (const unsigned long long);
  193. #endif
  194. // Other constructors.
  195. // cl_number (const char *);
  196. // Private pointer manipulations.
  197. cl_number (cl_private_thing);
  198. };
  199. // Private constructors.
  200. inline cl_number::cl_number (cl_private_thing ptr) : cl_gcobject (ptr) {}
  201. // The assignment operators:
  202. CL_DEFINE_ASSIGNMENT_OPERATOR(cl_number, cl_number)
  203. // The default constructors.
  204. inline cl_number::cl_number ()
  205. : cl_gcobject ((cl_private_thing) cl_combine(cl_FN_tag,0)) {}
  206. // The copy constructors.
  207. CL_DEFINE_COPY_CONSTRUCTOR2(cl_number,cl_gcobject)
  208. // Constructors and assignment operators from C numeric types.
  209. CL_DEFINE_INT_CONSTRUCTORS(cl_number)
  210. CL_DEFINE_INT_ASSIGNMENT_OPERATORS(cl_number)
  211. CL_DEFINE_LONG_CONSTRUCTORS(cl_number)
  212. CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(cl_number)
  213. #ifdef HAVE_LONGLONG
  214. CL_DEFINE_LONGLONG_CONSTRUCTORS(cl_number)
  215. CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(cl_number)
  216. #endif
  217. CL_DEFINE_FLOAT_CONSTRUCTOR(cl_number)
  218. CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number)
  219. // Hack section.
  220. // Conversions to subtypes without checking, template version:
  221. // the<cl_I>(x) converts x to a cl_I, without change of representation.
  222. template<class type>
  223. inline const type& the(const cl_number& x)
  224. {
  225. // check that sizeof(type)==sizeof(cl_number)
  226. typedef int assertion1 [1 - 2 * (sizeof(type) != sizeof(cl_number))];
  227. return *(const type *) &x;
  228. }
  229. // Conversions to subtypes without checking, macro version:
  230. // The(cl_I)(x) converts x to a cl_I, without change of representation.
  231. #define The(type) *(const type *) & cl_identity
  232. // This inline function is for type checking purposes only.
  233. inline const cl_number& cl_identity (const cl_number& x) { return x; }
  234. } // namespace cln
  235. // Conversions to subtypes:
  236. // As(cl_I)(x) returns x as a cl_I. It first checks that x is a cl_I
  237. // and then returns it without change of representation.
  238. #if 0 // no debug information
  239. #define As(type) type##_As
  240. #define CL_DEFINE_AS_CONVERSION(_class_) \
  241. extern const _class_& _class_##_As (const cl_number& x); \
  242. inline const _class_& _class_##_As (const _class_& x) { return x; }
  243. #else // Line number information for ease of debugging.
  244. #define As(type) type##_As cl_as_aux
  245. #define cl_as_aux(expr) (expr,__FILE__,__LINE__)
  246. #define CL_DEFINE_AS_CONVERSION(_class_) \
  247. extern const _class_& _class_##_As (const cl_number& x, const char * filename, int line); \
  248. inline const _class_& _class_##_As (const _class_& x, const char * filename, int line) { (void)filename; (void)line; return x; }
  249. #endif
  250. // Mutable(type,x);
  251. // x should be a variable `const type x' or `const type& x'.
  252. // This macro introduces a new variable `type& x' whose value can be
  253. // modified. Useful for modifying the argument of a function which takes
  254. // a `const type &x'.
  255. // Warning: To apply this to a function's formal parameter, a block { ... }
  256. // must be inserted.
  257. #define Mutable(type,x) \
  258. type __copied_##x = x; \
  259. type& x = __copied_##x;
  260. // DeclareType(type,x);
  261. // x should be a variable of some subtype of `cl_number'. type should be
  262. // a subtype of `cl_number'. A new variable of the given type is declared,
  263. // with name x and which refers to x (by reference, with const attribute).
  264. #define DeclareType(type,x) \
  265. const type& __tmp_##x = *(const type*) &x; \
  266. const type& x = __tmp_##x;
  267. #endif /* _CL_NUMBER_H */