[CLN-list] A silly program

Richard B. Kreckel kreckel at thep.physik.uni-mainz.de
Sat Nov 20 22:48:03 CET 2004


On Fri, 19 Nov 2004, Isidro [iso-8859-15] Cachadiña Gutiérrez wrote:
> I don't know if I'm wrong, but why are not defined elsewhere
>
> cln::operator-(const float , const cln::cl_R&)
>
> and some with double, etc. to compile this silly program.
>
> #include <cln/real.h>
> int main(int argc, char **argv)
> {
>   cln::cl_F a,b;
>   a=1;
>   b=1.0-a;
> }

Hmm, good question.  Did you notice that b=1-a works because there is
oerator-(int, const cl_F&)?  So, this looks like an omission to me. I'm
just wondering if it wouldn't be better to templatize the fallthrough case
after all the special integer inline helpers, like this:

template< typename T >
inline const cl_F operator+ (const T& x, const cl_F& y)
{ return cl_F(x) + y; }

and so on.  That should match anything that can be converted to cl_F,
then, in particular double and float.  I'm also wondering whether that
would be safe enough: maybe one could apply some cute traits-trick?  Or
maybe one shouldn't try to be clever and just write down the operators
in a straightfoward way since there are only two interesting cases?

Buena noche
  -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>




More information about the CLN-list mailing list