#### Archived

This topic is now archived and is closed to further replies.

# Bitwise operators on doubles

This topic is 6604 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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)

##### Share on other sites
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

##### Share on other sites
__int64 is a 64-bit integer value in MSVC 6.0

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

##### Share on other sites
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...)

##### Share on other sites
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

Edited by - Muzzafarath on June 18, 2000 7:00:45 AM

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631740
• Total Posts
3001965
×