GP32 What is the difference...


nerd of nerds

w00t!!!!
Joined
Feb 25, 2003
Messages
838
could someone explain to me the difference between floating point math and fixed point math? Also, would it be a good project for a begining programmer to go through the quake source and convert the floating point math to fixed point? :huh: Thanks
 
nerd of nerds:

It's simple, fixed point has a set number of decimal points, for example 16.16 which has 16 digits before the point and 16 after. Floating point has a literally 'floating' decimal point, so a 32-digit number could be 32 digits, no decimals, or 16 digits with 16 decimals, or 20 digits with 12 decimals, etc...

Floating point is useful for Quake, as it does a lot of calculations with them, and it needs the accuracy. The only real way to get rid of floating point would be to convert to fixed point, I would do it by multiplying all the numbers by a multiple of 10, but then again I'm an idiot :p

Not being familiar with the source I can't tell for sure, but on instinct, it would be better for a beginner to make simple game projects than work with a large project like that ... the bugs and annoyance is too much if you're likely to make mistakes :p

- Rico
 
The quake port was made using arm sdt, so i your dont have that you will have to write a beast of makefile, and i doubt you would like to learn makefile only to learn c.

Well if the quake source does compile for you yes do it. You might even be able to tweak it a little bit.
 
afaik gpquake was ported from pocketquake wich uses floating point already.
 
Inopia: Yeah but floating point is no problem for the pdas that ran it, they have huge processors, sometimes with dedicated FPUs to handle floating point numbers ... the gp32 grinds to a halt with them.

- Rico
 
After thinking about the first reply a while Heres what i got (probobly not right :D ) :
45676*1000=45676000
Would i just put a decimal before the 0s? like:
45676.000
And change some code? ;)
If i could have an example of how to convert a floating point number that would be great :)
 
more realistically -

numbers are stored
4.249033, 31.02493

We multiply by 1000000 (meeeellion)
4249033, 31024930

Do our calculations with 1M * the numbers ...

However let's say that number is actually the x co-ord of a pixel, which is rounded to int. We obviously don't want to draw at that, so we divide by a million again.

In practice it would be better to divide/multiply by a multiple of two, as all we need to do then is bit-shift, which is faster. Anyways it -could- work.

- Rico
 
The first reply was close, but not correct. Fixed point numbers use the bits of a 32-bit value. This can be divided in any way that you like.

For example, a 16.16 fixed point value is read: 0xwwwwffff, where wwww is the whole part of the number and ffff is the fractional part of the number.

Let's say we have a number: 1.0, and we want to represent it in 16.16 fixed point notation. Our number would be: 0x00010000 (or 64K).

Quickly you can see that in 16.16 fixed point math, the highest whole number you can have is 32K (signed) or 64K (unsigned).

The fractional portion is done, not as "digits" as the first reply stated, but rather as a fraction of a whole number. Since you are using 16-bits to represent your fraction, the highest fraction you can have is 0xFFFF or 0.9999847412109375 (0xFFFF/0x10000).

So, now if we want 4.5, that would be represented as: 0x00048000. Hope that makes sense.

What makes fixed-point math so much faster than floating point is that regular operations can be performed on fixed-point numbers:

2.5 + 4.5 = 7.0
0x00028000 + 0x00048000 = 0x00070000

Multiplication and division are only slightly more difficuly, but still much faster than floating point (when you don't have a FPU).

Jeff
 
I know this topic is old, but I have a question :p

What types are fixes point, and what are floating ©? Or do you have to do something to a normal var to make it fixed or loating or whatever? If I'm thinking right, "float" is floating, and "double" is fixed?
 
What types are fixes point, and what are floating ©? Or do you have to do something to a normal var to make it fixed or loating or whatever? If I'm thinking right, "float" is floating, and "double" is fixed?
Nope, float and double are both floating point types, just with different bit sizes. I believe that float is a 16-bit floating point type, whereas double is 32 bit?

In any case, the corresponding fixed-point types would be:

char (8-bit)
short (16-bit)
int (32-bit)

Note that most of the GP32 SDKs have the following typedefs:

u8 -> char
u16 -> short
u32 -> int

So that you can use "u16" for a 16-bit fixed-point number, or whatever.

Also, having seen this discussion, did anyone bring up floating point emulation? GCC/G++ does floating point emulation, where you can use floats and doubles, and it will internally convert the code to fixed-point math for you. This makes porting a lot easier, as you won't have to manually convert all the math used in your app.
 
Last edited by a moderator:
Back
Top