PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

FP resolution

Hi again,

FP calculation is based on int which are 4*8 bits (aren't they ?) with the standard FP_Q = 10, it means each number is multiplicated by 1024 so the resolution do no exceed 1/1024 (not far from 0.001) but numbers can go up to 2^((4*8-1)-10)=2 097 151

if we compare, floats have a resolution of 0.0000001 (no?) wich is much better in many case

it leads to strange behaviours when we translate a code from floats to FP.

so this is my questions:

why FP_Q is set to 10 when it could be set to 16 or 20 to stick with floats resolution ?

as it is a Constant in overloaded.h we come back to the old problem: no more common overloaded.dll if we change it ;)

could we have a way to set a variable FP_Q value (could be set for exemple at 10 by default and changed by a function call if necessary) ?

and the main question: did i miss something ? (which could be more than 75% chance huhu)
FP_Q about 12 should give you very stable results already , 10 is acceptable
if you increase FP_Q you decrease the number you can save. For example with 32bit ints and FP_Q=16 you're left with a number between -32768 and 32767... not really much. This could easily create many overflows and the whole engine would be a big mesh... (try to perform sqr with this resolution...:)
"floats have a resolution of 0.0000001 (no?)"

No, not really. The precision that fits in the fraction depends entirely on the number you store. The bigger the number the less bits left for the fraction. The smaller the number, the more bits you have for the fraction. This means that floating point numbers are accurate around zero, and very inaccurate around 10-million.

Anyway, this was not the intention of your post :). That our fixed point fractions are 10-bit is fairly arbitrary (or Jacco will come in and explain this EasyCE legacy). As far as my fixed point experience goes, 10 suffices for most applications.

If you need more, you have two options:

1. Use floats. Using floats in a few locations won't hurt performance that much. This is no GBA, but a PocketPC, remember? :)

2. Use your own fixedpoint format in those locations, converting from and to .10 format when communicating with the Overloaded libraries.

In what situation exactly do you need more precision?

Cheers,

Jape
hey,

i had the problem for a physical engine driving objects (time, gravity, speed, collisions, mass...)

these objects fit on screen, so their integer values are under 320 but their speed, acceleration, and other... can be very sharp values. the FP_Q 10 can give such a system some instability and crashes :')

well that's not very important in fact because the FP stuff is really easy to rewrite on our own FP_Q format and that shouldn't increase the final size of the prog ;)
Exactly, use your own fixedpoint format internally in the physics engine.

If you need any help, let us know.

Cheers,

Jape