diff --git a/ChangeLog b/ChangeLog index 4d2881d..b1b6e31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2000-08-29 Richard Kreckel + + * include/cln/number.h, the(const cl_number& x): New template + function. + 2000-08-26 Bruno Haible * autoconf/acgeneral.m4 (AC_OUTPUT): Use braces in exec_prefix default diff --git a/doc/cln.tex b/doc/cln.tex index d718288..73bb19c 100644 --- a/doc/cln.tex +++ b/doc/cln.tex @@ -747,15 +747,19 @@ class, using the @samp{As} and @samp{The} macros. @cindex @code{The()()} @code{The(@var{type})(@var{value})} assumes that @var{value} belongs to @var{type} and returns it as such. It is your responsibility to ensure -that this assumption is valid. +that this assumption is valid. Since macros and namespaces don't go +together well, there is an equivalent to @samp{The}: the template +@samp{the}. + Example: @example @group cl_I x = @dots{}; if (!(x >= 0)) abort(); - cl_I ten_x = The(cl_I)(expt(10,x)); // If x >= 0, 10^x is an integer. + cl_I ten_x_a = The(cl_I)(expt(10,x)); // If x >= 0, 10^x is an integer. // In general, it would be a rational number. + cl_I ten_x_b = the(expt(10,x)); // The same as above. @end group @end example diff --git a/include/cln/number.h b/include/cln/number.h index 1f02f3d..3c1da17 100644 --- a/include/cln/number.h +++ b/include/cln/number.h @@ -217,6 +217,16 @@ CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number) // Hack section. +// Conversions to subtypes without checking: +// the(x) converts x to a cl_I, without change of representation! +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))]; + return *(const type *) &x; +} + // Conversions to subtypes without checking: // The(cl_I)(x) converts x to a cl_I, without change of representation! #define The(type) *(const type *) & cl_identity