]> www.ginac.de Git - cln.git/commitdiff
* include/cln/number.h, the(const cl_number& x): New template
authorRichard Kreckel <kreckel@ginac.de>
Tue, 29 Aug 2000 21:16:59 +0000 (21:16 +0000)
committerRichard Kreckel <kreckel@ginac.de>
Tue, 29 Aug 2000 21:16:59 +0000 (21:16 +0000)
          function.

ChangeLog
doc/cln.tex
include/cln/number.h

index 4d2881de0dd463679be6d429f635783407ae43e1..b1b6e317e803435f3b09d9061ffeb2848994a177 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
index d718288bdf6923a9fede567be8e29475e04cff49..73bb19c277d01a2fa3aed2041091c1cfe4114bab 100644 (file)
@@ -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<cl_I>(expt(10,x)); // The same as above.
 @end group
 @end example
 
index 1f02f3df1596402f2a25ef984c3a965ca965207c..3c1da17b9e96b93338274067c976b9a40fc2c59c 100644 (file)
@@ -217,6 +217,16 @@ CL_DEFINE_DOUBLE_CONSTRUCTOR(cl_number)
 
 // 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