RE: Bit twiddling floating point numbers

2008-05-06 Thread Blubaugh, David A.
Sorry for the reply. I did not get your message until now. I was wondering if there was a way to develop floating-point mathematics package within a module. I was wondering if some of your work on bit twiddling floating - point numbers could be provided to me!!! Thanks. David Blubaugh

Re: Bit twiddling floating point numbers

2008-03-06 Thread [EMAIL PROTECTED]
On Mar 6, 11:00 am, Bryan Olson <[EMAIL PROTECTED]> wrote: > Mark Dickinson wrote: > > Jeff Goldfin wrote: > >> I can pack and unpack a float into a long > >> e.g. > >> struct.unpack('I',struct.pack('f',0.123))[0] > >> but then I'm not sure how to work with the resulting long. > > >> Any suggestion

Re: Bit twiddling floating point numbers

2008-03-06 Thread Bryan Olson
Mark Dickinson wrote: > Jeff Goldfin wrote: >> I can pack and unpack a float into a long >> e.g. >> struct.unpack('I',struct.pack('f',0.123))[0] >> but then I'm not sure how to work with the resulting long. >> >> Any suggestions? > > One alternative to using struct is to use math.ldexp and math.fr

Re: Bit twiddling floating point numbers

2008-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 11:27 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On Mar 5, 2:25 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > > Hi All > > > Is there a simple way to twiddle the bits of a float? In particular, I > > would like to round my float to the n most significant bits. > > > For exampl

Re: Bit twiddling floating point numbers

2008-03-05 Thread Mensanator
On Mar 5, 2:25 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi All > > Is there a simple way to twiddle the bits of a float? In particular, I > would like to round my float to the n most significant bits. > > For example - 0.123 in binary is 0.00011 > Rounding to 4 bits I get 0.0001. >

Re: Bit twiddling floating point numbers

2008-03-05 Thread Mark Dickinson
On Mar 5, 3:25 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I can pack and unpack a float into a long > e.g. > struct.unpack('I',struct.pack('f',0.123))[0] > but then I'm not sure how to work with the resulting long. > > Any suggestions? One alternative to using struct is to use math.ldexp

Re: Bit twiddling floating point numbers

2008-03-05 Thread Grant Edwards
On 2008-03-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > thanks for the reply but I'm still unsure as to how to > continue. Using the bitwise operators will help me deal with > integers but I really want to work with floats. In your original post, you said that you've got the values as integ

Re: Bit twiddling floating point numbers

2008-03-05 Thread [EMAIL PROTECTED]
On Mar 5, 10:48 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-03-05, Grant Edwards <[EMAIL PROTECTED]> wrote: > > > On 2008-03-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >> Any suggestions? > > > Just use the bitwise and/or/not operators: & | ~ > > Oh, I forgot to mention the shift

Re: Bit twiddling floating point numbers

2008-03-05 Thread Grant Edwards
On 2008-03-05, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-03-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> Any suggestions? > > Just use the bitwise and/or/not operators: & | ~ Oh, I forgot to mention the shift operators << and >> -- Grant Edwards grante

Re: Bit twiddling floating point numbers

2008-03-05 Thread Grant Edwards
On 2008-03-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Is there a simple way to twiddle the bits of a float? In particular, I > would like to round my float to the n most significant bits. > > For example - 0.123 in binary is 0.00011 > Rounding to 4 bits I get 0.0001. > > I can pack and

Bit twiddling floating point numbers

2008-03-05 Thread [EMAIL PROTECTED]
Hi All Is there a simple way to twiddle the bits of a float? In particular, I would like to round my float to the n most significant bits. For example - 0.123 in binary is 0.00011 Rounding to 4 bits I get 0.0001. I can pack and unpack a float into a long e.g. struct.unpack('I',struct.pack('f