josef.p...@gmail.com wrote:
> WindowsXP:
>
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on win32
struct.pack('>d', -0.0)
> '\x80\x00\x00\x00\x00\x00\x00\x00'
struct.pack(' '\x00\x00\x00\x00\x00\x00\x00\x80'
>
> Python 2.4.3 (#69, Mar 29 2006, 17:35:34
On Tue, Sep 29, 2009 at 6:48 PM, Christopher Barker
wrote:
>>> I'm assuming it's a bug that was fixed somewhere in between?
>
> It works on my 2.5, on a PPC:
>
> In [10]: struct.pack('>d', -0.0)
> Out[10]: '\x80\x00\x00\x00\x00\x00\x00\x00'
>
> In [11]: struct.pack(' Out[11]: '\x00\x00\x00\x00\x00
>> I'm assuming it's a bug that was fixed somewhere in between?
It works on my 2.5, on a PPC:
In [10]: struct.pack('>d', -0.0)
Out[10]: '\x80\x00\x00\x00\x00\x00\x00\x00'
In [11]: struct.pack('>> struct.pack('>d', -0.0)
'\x00\x00\x00\x00\x00\x00\x00\x00'
>>> struct.pack('http://mail.scipy.org/m
On Tue, Sep 29, 2009 at 16:49, Joe Kington wrote:
> Using 'd' rather than 'f' doesn't fix the problem...
>
> Python 2.3.4 (#1, Jan 9 2007, 16:40:09)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
import struct
Using 'd' rather than 'f' doesn't fix the problem...
Python 2.3.4 (#1, Jan 9 2007, 16:40:09)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
>>> struct.pack('d', -0.0)
'\x00\x00\x00\x00\x00\x00\x00\x80' <-
On Tue, Sep 29, 2009 at 16:37, Joe Kington wrote:
> I know it's a bit pointless profiling these, but just so I can avoid doing
> real work for a bit...
>
> In [1]: import sys, struct, math
>
> In [2]: def comp_struct(x):
> ...: # Get the first or last byte, depending on endianness
> ...:
I know it's a bit pointless profiling these, but just so I can avoid doing
real work for a bit...
In [1]: import sys, struct, math
In [2]: def comp_struct(x):
...: # Get the first or last byte, depending on endianness
...: # (using '>f' or ' 0: return False
: elif x < 0:
Christian Heimes wrote:
> How about using atan2()? :)
unless atan2 shortcuts for the easy ones, that doesn't strike me as
efficient (though with python function call overhead, maybe!).
Anyway, of course, some googling that I should have done in the first
place, revealed "double.py", from Martin
Christopher Barker wrote:
> Hi folks,
>
> This isn't really a numpy question, and I'm doing this with regular old
> python, but I figure you are the folks that would know this:
>
> How do I get python to make a distinction between -0.0 and 0.0? IN this
> case, I'm starting with user input, so:
On Tue, Sep 29, 2009 at 15:34, Christopher Barker wrote:
> Joe Kington wrote:
>> I just realized that what I'm doing won't work on older versions of
>> python, anyway...
>
> What I was looking for was which actual bit the sign bit is, as
> expressed as a native integer, so I can do a bitwise_and.
Joe Kington wrote:
> I just realized that what I'm doing won't work on older versions of
> python, anyway...
What I was looking for was which actual bit the sign bit is, as
expressed as a native integer, so I can do a bitwise_and.
But now that I think about it, I only need to test zero, not all
I just realized that what I'm doing won't work on older versions of python,
anyway...
Things work fine on 2.6
Python 2.6.2 (r262:71600, Sep 3 2009, 09:36:43)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import struct
On Tue, Sep 29, 2009 at 10:53 AM, Christopher Barker
wrote:
> Hi folks,
>
> This isn't really a numpy question, and I'm doing this with regular old
> python, but I figure you are the folks that would know this:
>
> How do I get python to make a distinction between -0.0 and 0.0? IN this
> case, I'm
Christopher Barker wrote:
> Pauli Virtanen wrote:
>
>> Tue, 29 Sep 2009 09:53:40 -0700, Christopher Barker wrote:
>> [clip]
>>
>>> How can I identify -0.0?
>>>
>> signbit
>>
>>
>
> perfect for numpy, but at this point I don't have a numpy dependency
> (very unusual for my code!
Well, this is messy, and nearly unreadable, but it should work and is pure
python(and I think even be endian-independent).
struct.unpack('b',struct.pack('>d', X)[0])[0] >= 0
(where X is the variable you want to test)
In [54]: struct.unpack('b',struct.pack('>d',0.0)[0])[0] >= 0
Out[54]: True
In [
On 09/29/2009 12:08 PM, Gökhan Sever wrote:
On Tue, Sep 29, 2009 at 11:53 AM, Christopher Barker
mailto:chris.bar...@noaa.gov>> wrote:
Hi folks,
This isn't really a numpy question, and I'm doing this with
regular old
python, but I figure you are the folks that would know thi
Pauli Virtanen wrote:
> Tue, 29 Sep 2009 09:53:40 -0700, Christopher Barker wrote:
> [clip]
>> How can I identify -0.0?
>
> signbit
>
perfect for numpy, but at this point I don't have a numpy dependency
(very unusual for my code!). Anyone know a pure-python way to get it?
It seems I should be
On Tue, Sep 29, 2009 at 11:53 AM, Christopher Barker
wrote:
> Hi folks,
>
> This isn't really a numpy question, and I'm doing this with regular old
> python, but I figure you are the folks that would know this:
>
> How do I get python to make a distinction between -0.0 and 0.0? IN this
> case, I'm
Tue, 29 Sep 2009 09:53:40 -0700, Christopher Barker wrote:
[clip]
> How can I identify -0.0?
signbit
--
Pauli Virtanen
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Hi folks,
This isn't really a numpy question, and I'm doing this with regular old
python, but I figure you are the folks that would know this:
How do I get python to make a distinction between -0.0 and 0.0? IN this
case, I'm starting with user input, so:
In [3]: float("-0.0")
Out[3]: -0.0
so
20 matches
Mail list logo