| Author |
bit twiddling with floating point primitives
|
Leroy J Brown
Ranch Hand
Joined: Dec 02, 2007
Posts: 71
|
|
|
Is there a reason that bit-shifts and bitwise twiddling is not allowed on doubles and floats?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
Originally posted by Tristan Rouse: Is there a reason that bit-shifts and bitwise twiddling is not allowed on doubles and floats?
Actually, you can... it just isn't very useful to do so. If you want, you can get the raw bits, using the Double class, and shift them (you can also put the raw bits back with the Double class).... but why? Floating point is stored in an IEEE format, which is really really complicated -- storing the mantissa and exponent together, along with normalization, and special patterns for specific values (like infinity). Shifting these values just doesn't make sense. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 10043
|
|
it would sort of like shifting all the letters in a sentence over one word. i twoul dsor to flik eshiftin gal lth eletter si n asentenc eove ron ewor. you can do it, but why? the results are more or less meaningless.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
Gagree. Dbu twit hfloatin gpoint, si ti seve nmor emeaningles. Swit hcharacter, sa tleas tther ei s achanc et ounderstan dwha ti sgoin go. Nwit hth EIEE efloatin gpoin tstandar, di ti sjus tto ocomplicate dt ounderstan, deve nwithou tth ebi tshiftin. Enryh
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
link
|
 |
 |
|
|
subject: bit twiddling with floating point primitives
|
|
|