About binary operations

BlitzMax Forums/BlitzMax Programming/About binary operations

KillerHunter(Posted 2007) [#1]
Hello guys,

I've just a minor question. I was wondering why I can not use binary operations on double. I need like 10 or 12 bits for a type, but the debugger says that I can't use double with binary. I'll use an integer then, but why exactly I can't use double?

Thank you.


H&K(Posted 2007) [#2]
Because it has a decimal place, whereas the binary operations (By definition), dont have anything "Decimal" about them at all.

Glib answer I Know, but thats the reason. From a technical point of view there is no reason why you cannot, for after all the are just a string of Binary didgits. Its simply down to the fact, that you would have loads of problems standardising a system that is in essence Two different number systems. So the Lang writters simply dont bother. Any time you think that you need to do it, you probably shouldnt, or should use an INT, which is afer all 32bit in Bmax, so you could if you wanted store two of you "12" in them. (Two shorts next to each other are also stored as an int, so Bmax would just be doing a 16 Shl in the backgruond)

PPl frown on this "Union" use nowadays, saying that you have enough memory anyway, so why bother, and there is a thread about it somewhere.


FlameDuck(Posted 2007) [#3]
I was wondering why I can not use binary operations on double.
Because it's nonsensical?


Steffenk(Posted 2007) [#4]
Maybe he should use a 'Long'?


Azathoth(Posted 2007) [#5]
If he only needs 10-12 bits couldn't he just use an int or even a short?


H&K(Posted 2007) [#6]
If he only needs 10-12 bits couldn't he just use an int or even a short?
Are my answers not appering to other ppl then?


ImaginaryHuman(Posted 2007) [#7]
You can convert the Double to a Long by multiplying it by x^10 to shift if left and store it in the Long, then do your bit stuff on the long, then put it back into a double and divide by x^10. But it will lose some accuracy. You can't rely on setting/unsetting bits and have them be sure to be preserved as you convert format.