Boost logo

Boost :

From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2008-02-27 10:47:01

----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Johan Råde Sent: 27
February 2008 15:33 To: boost_at_[hidden]
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
Telephone: +44 1223 441434 / 203894 (direct)
Fax: +44 1223 203999
Email: martin.bonner_at_[hidden]

Boost list run by bdawes at, gregod at, cpdaniel at, john at