Floating point vs. Interger

Started by
7 comments, last by UraniumRod 24 years, 6 months ago
Someone correct me if I'm wrong, but with today's processors (the pentium and up), floating point is no longer considered a problem of speed. So as for the difference between the two nowadays, who knows, because I'm not sure if anyone still uses fixed point, at least very often.

Kevin

Admin for GameDev.net.

Advertisement
Since the Pentium, the floating point multiply instruction has actually been faster than the integer multiply instruction.

With today's hardware, there's very little need to do fixed point anymore. It's not worth the trouble.

I mean even if you could make a fixed point math library that was slighly faster than a floating point one, the extra code and development effort you'd spend getting around precision errors would cause a lot of pain and wasted time.

------------------
-vince


-vince


if you plan to convert your floats to integers often, it might be worth using fixed point.

the only time i really used fixed point agressively was in a bitmap scaling routine (written in asm), where subpixel coordinates had to be converted to screen coordinates, which only required a bit shift. I don't think it would have been as fast using floating point numbers, and rounding them every pixel!

About the only market left where using fixed point is an advantage is PSX development.
However, if you are thinking of doing conversions between types then definately be careful about how often and where you do them, they can account for a lot of processor speed.
Floating point math is fast, integer math is fast. But converting from floating point to integer is slow. For those functions that convert from floating point to integer often use fixed point.
Floating point is now FASTER than integer math... plus the floating point operations can be done in parallel if coded right. Fixed point is dead.
Fixed point is still very useful at times.

The pentium does have a separate FP module which makes floating point instructions execute in parallel. However, if you are going to be accessing the FP variables often your best bet is to use fixed point math.

There are certain situations for everything and there is no "right" answer all of the time. The trick is to time your code and test out your theories. Something that somebody tells you is useless may give you that extra speed-up you need.

For example, I have a floor/ceiling mapper in my current game. I converted it to Fixed point and I was rewarded with a frame rate increase of almost 3x. Yet, I -re-coded the rest of the enging to use fixed point and I didn't receive even a 1 FPS increase. The reason, I wasn't accesing the values often enough for it to matter.

If I would have never tried it out, then I would have missed out on that great speed improvement. It is your call. Personally, I never pay much attention to what people tell me will/won't work ...I tru for myself and see.

- Chris


How slow is Floating point math to that of Fixed point int math?

2x, 3x slower or what?


UraniumRod

------------------------------"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
Yeah, a couple years ago I wrote a very simple raycasting engine in C using a 16-bit compiler. It was much faster using fixed-point math than floating-point, because the rays all had to be converted to fixed-point to find the screen coordinates.

It seem to me that rendering code is usually fastest as fixed-point, since screen coordinates always need to be integers, but the more high-level code can remain floating-point. Like what Chris said.

------------------
~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement