
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Johan RĂ¥de Sent: 27 February 2008 15:33 To: boost@lists.boost.org Subject: Re: [boost] Ann: Floating Point Utilities Review starts today
There is one other useful function worth having IMO:
template <class T> int sign(T x);
returns 0 (x is zero), +1 (x is > 0) or -1 (x is < 0). This is trivial to implement (lot's of old C code - for example the Numerical Recipies stuff - implement this as a helper macro), and there's an undocumented version currently in Boost.Math. Is this worth integrating with Johan's code? I've found it quite useful in Boost.Math from time to time.
What should this function return for a NaN?
well, using INT_MIN would preserve the identify sign(-x) == -sign(x) even for x=NAN on many platforms. Note: this is not an entirely serious suggestion. Seriously, I would have thought either "unspecified" or throw or pick a value. I think it's probably an error to call this with a NAN. From: Peter Bartlett
A NaN?
Tricky. sign was specified as returning "int" (and I think that's probably right). -- Martin Bonner Senior Software Engineer/Team Leader PI SHURLOK LTD Telephone: +44 1223 441434 / 203894 (direct) Fax: +44 1223 203999 Email: martin.bonner@pi-shurlok.com www.pi-shurlok.com disclaimer