Jump to content
IGNORED

Fixed point arithmetics


Recommended Posts

In here are many small parts of what you want:

http://codebase64.org/doku.php?id=base:6502_6510_maths

 

I'm afraid there's no "all in one" library.

 

Functions like sin, log etc. are usually done with tables.

Working with fixed point math is like working with integers. You just take the part of result you want.

Plenty of integer routines on the codebase64...

  • Like 1
Link to comment
Share on other sites

From what I recall of Elite, your X, Y and Z position in space uses a fixed point representation of 3 bytes each. This is little more magic than using the low byte as the fractional part (0/256 -> 255/256) and the middle byte as the low integer (0 -> 255) and the high byte as high integer part (256 × (0 -> 255)).

Operations work similar to usual integer math but after a multiply you take the result from the 2nd byte upwards, effectively dividing your result by 256.

 

The top three rows show the breakdown of 2 values to be multiplied and the result.

On the right are the same bytes represented as an 24-bit integer.

The lower line then splits the result from multiplying those back into its component bytes.

This shows us the that result is obtained by (effectively) dividing by 256.

 

Similarly, a division is done by first multiplying the dividend by 256 (copy it one byte higher).

Note though the precision loss. A12 is A10 / A11 but A14 is the actual value represented by the final value.

 

This gives a range of 0 -> 65535+(255/256).

But IIRC Elite might treat this a signed and the 8th bit of the high byte is the sign bit.

Hence you'd then have a range of around the +/- 32768 range.

post-1822-0-34624900-1463239585_thumb.gif

Edited by Wrathchild
  • Like 1
Link to comment
Share on other sites

I don't want to offend anyone, who wants to help, but I had asked for a library, not explanations of fixed point.

The four base operation are not the problem.

The problem are all the stuff like sin, log etc.

But there seem to be no library for that stuff, so I will have to program that myself.

Edited by JoSch
Link to comment
Share on other sites

The problem are all the stuff like sin, log etc.

But there seem to be no library for that stuff, so I will have to program that myself.

What's the purpose if I may ask ?

 

Trig. functions are used often in demos, games etc. but I can't think of where one would use Log ? (beside to do fast mul-div ...)

Link to comment
Share on other sites

What's the purpose if I may ask ?

 

Trig. functions are used often in demos, games etc. but I can't think of where one would use Log ? (beside to do fast mul-div ...)

Well, log will not be needed directly, but IIRC there are implementations of sqrt, which use that. My point really was to have a complete library.

 

 

 

You can find the cc65-fixed-point-part for sin/cos here:

 

https://github.com/cc65/cc65/blob/master/libsrc/common/cc65_sincos.s

Nice find. I didn't see that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...