fixed point / floating point

This is a discussion on fixed point / floating point within the Game Programming forums, part of the General Programming Boards category; I've read in many old 3D graphics tutorials that fixed point math is a lot faster than floating point math, ...

  1. #1
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916

    fixed point / floating point

    I've read in many old 3D graphics tutorials that fixed point math is a lot faster than floating point math, but I also read in a more recent document on pentium optimizations that the FPU can do most floating point operations in one clock cycle, so I don't know what to believe. So I turn to the Cboards with this question...is there any performance boost to be had out of spending hours implementing fixed point math in my 3D engine, or is floating point just as fast, or even faster? I don't want to spend a ton of time on something that isn't going to make anything faster...

  2. #2
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    back in the day [i always wanted to say that] when math coprocessors didn't always co-exist, or FPUs for that matter, yes a thing like this would help you out. but nowadays, especially with more energy put into fp operations, processor wise, it would probably not be worth your time to implement it. it's usage was an advantage you won't get so much of, if any, with your current generation processors, but they mention it anyway which is always good to know. i wouldn't recommened putting your time into that, clever programming can also give you that slack that you need anyhow. i'm sure you'll find ways to cut some of those operations off of your runtime, good luck...
    hasafraggin shizigishin oppashigger...

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    okay, that's cool...I've already done a ton to optimize the amount of math in my routines, so if fixed point math isn't going to help, I'm happy, because it would have been a pain anyway.

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    yeah i mean so long as you're happy with the results that'll do ya... and if you need to add more later, then that just means more number crunch crunching y'know? more power to you...
    hasafraggin shizigishin oppashigger...

  5. #5
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    A little history, first:
    -------------------------
    Prior to the Pentium III, integer math was always much faster than floating point math. In fact, many processors were sold without FPUs (Floating Point Units) and so the floating point work was handled by other highly optimized methods. However, Intel in particular, saw the way things were going with entertainment software and addressed the issue of speeding up floating point in their CPUs.

    With Intel, Floating Point is now much faster than integer math.

    ---

    Fixed Point math (which many older games used in order to gain precision but with integer values) is really very straightforward:

    Let's say you want to use fixed point math. You would use a long because it has 32-bits (more bits means more precision). Then, based on the biggest whole number you might have, you would use enough bits to represent that maximum value, and then all the rest of the bits would be used for fractional amounts (precision).

    MSB <-- LSB

    01100010 000100000110000001011101

    In the above, the Most Significant Bit (Bit worth the most) is on the left. I've divided the binary at the point where the decimal point would be located.

    Since you have 8-bits on the left, the largest number you could have is from -127 to +127, or 0 to 255. The remaining 24 bits could be used for precision.

    The compiler and computer have no idea you are working with your own pseudo-floating-point. All they see is a 32-bit integer.

    You could have any number of bits to the left and right of the decimal point, so long as all the bits combined were no greater than your maximum integer bit-length (32 in this case). The fewer bits used on the MSB end, the more bits could be used on the LSB end, adding greater precision with each bit.

    This was a very clever way to get around a very real limitation 3D game development and scientific programs.
    It is not the spoon that bends, it is you who bends around the spoon.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 09:14 PM
  2. Floating point #'s, why so much talk about it?
    By scuzzo84 in forum C Programming
    Replies: 5
    Last Post: 09-20-2005, 05:29 PM
  3. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  4. floating point exception? what causes these?
    By salvelinus in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2002, 01:12 PM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21