function.
+2000-08-29 Richard Kreckel <kreckel@ginac.de>
+
+ * include/cln/number.h, the(const cl_number& x): New template
+ function.
+
2000-08-26 Bruno Haible <haible@clisp.cons.org>
* autoconf/acgeneral.m4 (AC_OUTPUT): Use braces in exec_prefix default
@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<cl_I>(expt(10,x)); // The same as above.
@end group
@end example
// Hack section.
+// Conversions to subtypes without checking:
+// the<cl_I>(x) converts x to a cl_I, without change of representation!
+template<class type>
+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