mailRe: The name clash of 'float.py' with the builtin function 'float()' and bits vs. bytes.


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Gary S. Thompson on November 13, 2006 - 11:29:
Edward d'Auvergne wrote:

I've just noticed an important name clash with 'float.py'. The module
name clashes with the inbuilt function 'float()'. Hence if you import
float rather than it's functions, you will no longer have access to
the 'float()' function. Gary, do you think the module should be
renamed to something like 'ieee_754.py'? Or maybe 'fp_754.py'?


my original name was ieeefloat if that is any help!

Any
other ideas?  I would guess that to eventually get it distributed with
Python as a standard module (possibly replacing 'fpconst.py' if that
ever gets into Python), the name clash would need to be resolved.

I was also wondering if there was an advantage working with bytes and
hexadecimal rather than plain bits (as a string or array of 1 and 0's)
in 'float.py'?  Is this necessary because of the 'struct' module
functions 'pack()' and 'unpack()'?  Does it help with the endianness
issues?

It doesn't help with endianness issues I worked in hex and documented in bits as well because many computer scientists think in hex and writer constants in hex and hex is supported by python whereas binary strings of the form 0001000 etc aren't

Another question I have is in the docstring of the SIGNBIT byte, you
say the sign bit in bytes is '0b00000001'.  Did you mean '0b10000000'?

If I remember correcly I am using little endian representations for bytes and that gives this format. I would quite like to convert to big endian as this is easier to read (if not to debug on a little endian machine) but was leaving it until afetr the unit test suite was complete ;-)


Or are you representing position 63 of the double precision float bit
pattern on the far right?  Oh and one last thing, does 'packed[::-1]'
properly reverse the byte order?  For example:

   packed = pack('d', 1.0e-25)  ->  '\xd9}\xda\xf5\xd0\xf2\xbe:',
   packed[::-1]  ->  ':\xb3\xf2\xd0\xf5\xda}\xd9'.

yes it does! The :} and other gumph will just be the ascii representation of the relevant hex (n.b. how did you print out these strings.... the last bit on one of the seems strange, I will investigate)

To print hex I use

packed = pack('d', 1.0e-25)
for elem in unpack('8B',packed):
  print hex(elem)

I have no idea what the ':' or '}' mean here, but should the string be
'\xbe:\xf2\xd0\xf5\xda\xd9}'?  Would using the first characters '<'
and '>' be a better way of supporting little and big endianness?


can you point me to a relevant line where you want to use < or make a suggestion of what you want to do I wasn't clear on this

regards
gary


Cheers,

Edward

_______________________________________________
relax (http://nmr-relax.com)

This is the relax-devel mailing list
relax-devel@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel

.



--
-------------------------------------------------------------------
Dr Gary Thompson
Astbury Centre for Structural Molecular Biology,
University of Leeds, Astbury Building,
Leeds, LS2 9JT, West-Yorkshire, UK             Tel. +44-113-3433024
email: garyt@xxxxxxxxxxxxxxx                   Fax  +44-113-2331407
-------------------------------------------------------------------





Related Messages


Powered by MHonArc, Updated Mon Nov 13 14:00:32 2006