Bitwise operators on doubles

Started by
7 comments, last by Muzzafarath 23 years, 10 months ago
Is it possible to use bitwise operators on doubles/long doubles? You can do it on floats by first casting the float to a long and then doing the bitwise stuff on the long, and then casting it back to a float. This works since floats and longs are 32 bits, but a double has 64 bits and a long double has 96 bits (on my machine) and I haven''t heard of any integer type that''s 64 or 96 bits wide /. Muzzafarath Mad House Software
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Advertisement
You can use signed or unsigned ints and longs. I do not know that I would recommend using doubles or floats, though I don''t see any real reason why you couldn''t.

Kressilac
ps why do you need to track a bit using a float? Use an integer based type. I have to think it is more efficient and possibly faster.(I can''t support this though)
Derek Licciardi (Kressilac)Elysian Productions Inc.
In VC++ 6.0 you can use INT64 and UINT64 to get signed/unsigned integers 64 bits wide. I think it works if you include windows.h
__int64 is a 64-bit integer value in MSVC 6.0
You can also do it with pointers. Anyway don''t use floating point; use fixed point. Its much faster and cooler.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
Actually, blue-lightning, floating point math is very fast, and can be faster than integer math on Pentiums, because they have a Floating Point Unit that can perform floating point operations in parallel with other operations. I read in a 3d engine book that using fixed points rather than floating points can actually slow the game down on Pentium and above processors (although I forgot what the reasoning was...)
quote: Original post by blue-lightning

You can also do it with pointers. Anyway don't use floating point; use fixed point. Its much faster and cooler.


Actually, on most new computers, floating point is just as fast, or even faster, than fixed point because of the FPU. The reason is that when doing fixed point stuff, you have to bit-shift and stuff like that to get it to work, while floating point has its own CPU instructions (I think).

quote: Original post by kressilac
ps why do you need to track a bit using a float? Use an integer based type. I have to think it is more efficient and possibly faster.(I can't support this though)


No reason. I just wanted to know how to do it It is probably faster to do it on integer types since you don't have to cast it back and forth. I suppose it can be useful to know how to do it if you want really big bitfields, and you want to use a double instead of two longs

/. Muzzafarath
Mad House Software

Edited by - Muzzafarath on June 18, 2000 7:00:45 AM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Casting doesn''t take any CPU time unless the operator is overloaded. And also for the way I use fixed point I don''t have to shift, but I will agree that multiplying a fixed point by another fixed point is slow.

For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
For a good time hit Alt-F4! Go ahead try it, all the cool people are doing it.
Although casting doesn''t take any CPU time, I''m pretty sure the conversion from float to int and vice versa would take some time, since floating points are encoded in IEEE and integers are just straight binary numbers... It''s doing more than a reinterpretation of types when you convert between float and int, so it probably takes some CPU time. If it didn''t, then nobody would ever warn people to hold off on the conversion until the very last minute.

This topic is closed to new replies.

Advertisement