X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=include%2Fcln%2Fnumber.h;h=67f68899a6926eca49722f012d0a20d159162c57;hb=HEAD;hp=2467d38aa0c49861f7de69155aa510cee3965420;hpb=f6b8e7b68cb9d636d2658b56847bff69dc89936a;p=cln.git diff --git a/include/cln/number.h b/include/cln/number.h index 2467d38..67f6889 100644 --- a/include/cln/number.h +++ b/include/cln/number.h @@ -25,6 +25,18 @@ // Constructors and assignment operators from C numeric types. +#ifdef _MSC_VER +// Workaround to force MSVC to tag the symbol with the cln:: namespace +// When declaring inside an inlined function the symbol is placed in the +// global namespace! +namespace cln { +extern cl_private_thing cl_I_constructor_from_L (sint32 wert); +extern cl_private_thing cl_I_constructor_from_UL (uint32 wert); +extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); +extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); +} +#endif + #define CL_DEFINE_INT_CONSTRUCTOR(_class_,_type_) \ inline _class_::_class_ (const _type_ wert) \ { \ @@ -109,40 +121,67 @@ inline _class_& _class_::operator= (const unsigned long wert) \ } #endif +#if (long_long_bitsize==64) +// `long' == `sintQ', `unsigned long' == `uintQ'. +#define CL_DEFINE_LONGLONG_CONSTRUCTORS(_class_) \ +inline _class_::_class_ (const long long wert) \ +{ \ + extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \ + pointer = cl_I_constructor_from_Q(wert); \ +} \ +inline _class_::_class_ (const unsigned long long wert) \ +{ \ + extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \ + pointer = cl_I_constructor_from_UQ(wert); \ +} +#define CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(_class_) \ +inline _class_& _class_::operator= (const long long wert) \ +{ \ + extern cl_private_thing cl_I_constructor_from_Q (sint64 wert); \ + cl_dec_refcount(*this); \ + pointer = cl_I_constructor_from_Q(wert); \ + return *this; \ +} \ +inline _class_& _class_::operator= (const unsigned long long wert) \ +{ \ + extern cl_private_thing cl_I_constructor_from_UQ (uint64 wert); \ + cl_dec_refcount(*this); \ + pointer = cl_I_constructor_from_UQ(wert); \ + return *this; \ +} +#endif namespace cln { // Constructors and assignment operators from C numeric types. // from `float': -union ffloatjanus; -extern cl_private_thing cl_float_to_FF_pointer (const union ffloatjanus& val); +extern cl_private_thing cl_float_to_FF_pointer (const float val); #define CL_DEFINE_FLOAT_CONSTRUCTOR(_class_) \ inline _class_ :: _class_ (const float x) \ { \ - pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \ + pointer = cl_float_to_FF_pointer(x); \ } \ inline _class_& _class_::operator= (const float x) \ { \ cl_dec_refcount(*this); \ - pointer = cl_float_to_FF_pointer(*(const union ffloatjanus *)&x); \ + pointer = cl_float_to_FF_pointer(x); \ return *this; \ } // from `double': -union dfloatjanus; -extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const union dfloatjanus& val); +extern struct cl_heap_dfloat * cl_double_to_DF_pointer (const double val); #define CL_DEFINE_DOUBLE_CONSTRUCTOR(_class_) \ inline _class_::_class_ (const double x) \ { \ - pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \ + pointer = cl_double_to_DF_pointer(x); \ } \ inline _class_& _class_::operator= (const double x) \ { \ cl_dec_refcount(*this); \ - pointer = cl_double_to_DF_pointer(*(const union dfloatjanus *)&x); \ + pointer = cl_double_to_DF_pointer(x); \ return *this; \ } @@ -164,6 +203,8 @@ public: cl_number (const unsigned int); // argument must be < 2^29 cl_number (const long); cl_number (const unsigned long); + cl_number (const long long); + cl_number (const unsigned long long); cl_number (const float); cl_number (const double); cl_number& operator= (const int); // |argument| must be < 2^29 @@ -172,6 +213,8 @@ public: cl_number& operator= (const unsigned long); cl_number& operator= (const float); cl_number& operator= (const double); + cl_number& operator= (const long long); + cl_number& operator= (const unsigned long long); // Other constructors. // cl_number (const char *); // Private pointer manipulations. @@ -192,15 +235,12 @@ CL_DEFINE_INT_CONSTRUCTORS(cl_number) CL_DEFINE_INT_ASSIGNMENT_OPERATORS(cl_number) CL_DEFINE_LONG_CONSTRUCTORS(cl_number) CL_DEFINE_LONG_ASSIGNMENT_OPERATORS(cl_number) +CL_DEFINE_LONGLONG_CONSTRUCTORS(cl_number) +CL_DEFINE_LONGLONG_ASSIGNMENT_OPERATORS(cl_number) CL_DEFINE_FLOAT_CONSTRUCTOR(cl_number) CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number) -// Conversion: -//inline cl_N& cl_as_N (const cl_number& x) -//{ return *(cl_N*)(&x); } - - // Hack section. // Conversions to subtypes without checking, template version: @@ -209,7 +249,8 @@ template inline const type& the(const cl_number& x) { // check that sizeof(type)==sizeof(cl_number) - typedef int assertion1 [1 - 2 * (sizeof(type) != sizeof(cl_number))]; + static_assert(sizeof(type)==sizeof(cl_number), + "sizeof(type)!=sizeof(cl_number)"); return *(const type *) &x; } // Conversions to subtypes without checking, macro version: @@ -225,16 +266,16 @@ inline const type& the(const cl_number& x) // As(cl_I)(x) returns x as a cl_I. It first checks that x is a cl_I // and then returns it without change of representation. #if 0 // no debug information - #define As(type) as_##type + #define As(type) type##_As #define CL_DEFINE_AS_CONVERSION(_class_) \ - extern const _class_& as_##_class_ (const cl_number& x); \ - inline const _class_& as_##_class_ (const _class_& x) { return x; } + extern const _class_& _class_##_As (const cl_number& x); \ + inline const _class_& _class_##_As (const _class_& x) { return x; } #else // Line number information for ease of debugging. - #define As(type) as_##type cl_as_aux + #define As(type) type##_As cl_as_aux #define cl_as_aux(expr) (expr,__FILE__,__LINE__) #define CL_DEFINE_AS_CONVERSION(_class_) \ - extern const _class_& as_##_class_ (const cl_number& x, const char * filename, int line); \ - inline const _class_& as_##_class_ (const _class_& x, const char * filename, int line) { (void)filename; (void)line; return x; } + extern const _class_& _class_##_As (const cl_number& x, const char * filename, int line); \ + inline const _class_& _class_##_As (const _class_& x, const char * filename, int line) { (void)filename; (void)line; return x; } #endif // Mutable(type,x);