From: Cromwell Enage (sponage_at_[hidden])
Date: 2005-10-27 08:23:07
--- Simon Buchan wrote:
> David Abrahams wrote:
> > my_rational<x,1> can be an integral constant *at
> > compile time*. I'm not sure it's useful, but
> > it's not insane.
> If you for some reason still think this, why not
> eagerly evaluate
> template<typename Num>
> to Num, since we are already eagerly normalising?
It's possible to do so, but I see three concerns.
One, we need to be careful where to do it. Putting
this capability directly in the definition of rational
makes expressions like rational<int_<4> > rather
Employing downcasting on the result of each rational
operation leads us to the second concern: performance.
Computationally heavy numeric metafunctions (e.g.
exponential, sine) are going to pay extra at each step
checking for an event that may never occur. And even
if downcasting occurs half the time, if there are just
as many regular casts back to rational, we end up
overpaying twice as much.
We could give users the ability to explicitly downcast
any numeric constant. This leads us to the final
concern: usefulness. For the moment, I don't see any
need beyond rounding; the library provides a numeric
metafunction called whole_part if you want truncation.
If anybody needs either downcasting or rounding, we'd
like to hear from you.
Cromwell D. Enage
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk