Browse Source

* include/cln/number.h, the(const cl_number& x): New template

function.
master
Richard Kreckel 25 years ago
parent
commit
1277b4cb29
  1. 5
      ChangeLog
  2. 8
      doc/cln.tex
  3. 10
      include/cln/number.h

5
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

8
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<cl_I>(expt(10,x)); // The same as above.
@end group
@end example

10
include/cln/number.h

@ -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

Loading…
Cancel
Save