Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-09-30 11:18:45


> At the risk of being irritating, I'm going to ask just the opposite
> question. ;-)
>
> Why is hypot (for example) templated?

Good question, I needed hypot to implement some of the complex number stuff,
and it's a template because it was possible to make it one :-)

> template <class T>
> T hypot(T x, T y);
>
> If the intent is to implement 8.16.4 (from N1836), I don't think this
> does it. Consider this test for example:

I'm aware of those nasties, but <cmath> is *not* part of the current
submission, well that's my excuse anyway. Basically hypot/log1p/expm1 are
some internals I needed and it seems a shame not to expose them in
Boost.Math.

I have jumped though hoops however to make sure that <complex> does the
right thing with for example:

polar(2.3, char(1)); // expression returns a std::complex<double>

> Also do we want to support infinities and nans?
>
> assert(hypot(INFINITY, sqrt(-1.)) == INFINITY);

Hmm, what does C99 say about this, I can see anything obvious at first
glance? Your suggestion matches what the complex number functions are
required to do however, so it's probably in there somewhere, I just can't
see it at present. I'm not sure I handle range errors correctly either
(setting errno that is).

It would certainly be easy enough to convert those functions into
non-template inlines that forward to the template implementation, and make
them C99 conforming in the process (once I've figured out what that is!)

Thanks for raising this,

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net