• Post Reply Bookmark Topic Watch Topic
  • New Topic

bit twiddling with floating point primitives  RSS feed

 
Leroy J Brown
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason that bit-shifts and bitwise twiddling is not allowed on doubles and floats?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
link


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!