Re: [Numpy-discussion] Portable functions for nans, signbit, etc.

2008-10-02 Thread David Cournapeau
On Thu, Oct 2, 2008 at 11:41 AM, Charles R Harris
[EMAIL PROTECTED] wrote:


 Which is rather clever. I think binary_cast will require some pointer abuse.

Yep (the funny thing is that the bit twiddling will likely end up more
readable than this C++ stuff)

cheers,

David
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Portable functions for nans, signbit, etc.

2008-10-02 Thread Charles R Harris
On Thu, Oct 2, 2008 at 2:41 AM, David Cournapeau [EMAIL PROTECTED] wrote:

 On Thu, Oct 2, 2008 at 11:41 AM, Charles R Harris
 [EMAIL PROTECTED] wrote:

 
  Which is rather clever. I think binary_cast will require some pointer
 abuse.

 Yep (the funny thing is that the bit twiddling will likely end up more
 readable than this C++ stuff)


The zip file has the bit twiddling, which is worth looking at if only for
the note on the PPC extended precision. Motorola seems to  be a problem but
I don't think we support any of the 66xx series.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Portable functions for nans, signbit, etc.

2008-10-01 Thread Charles R Harris
The normal signbit function of gcc without the -std=c99 flag doesn't work
correctly for nans and infs. I found the following code on a boost mailing
list and it might be helpful here for portability.

const boost::uint32_t signbit_mask
 = binary_castboost::uint32_t(1.0f)
 ^ binary_castboost::uint32_t(-1.0f);

inline bool signbit(float x)
{
 return binary_castboost::uint32_t(x)  signbit_mask;
}

inline bool signbit(double x)
{
 return signbit(static_castfloat(x));
}
inline bool signbit(long double x)
{
 return signbit(static_castfloat(x));
}

Which is rather clever. I think binary_cast will require some pointer abuse.
There are a bunch of other boost functions here
http://tinyurl.com/3tvj9uthat might prove useful. This file

 goog_1222871357985floating_point_utilities_v3.zip
http://www.boostpro.com/vault/index.php?action=downloadfilefilename=floating_point_utilities_v3.zipdirectory=Math%20-%20NumericsPHPSESSID=64b789bb8092caa29b11839ec7526611
portable isnan, fpclassify, signbit etc. + facets for portable handling of
infinity and NaN in text streams

Looks particularly interesting. It's a bit large for the mailing list so I
won't attach it. The Boost license should be compatible with numpy.

Chuck
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion