Re: [cc65] Floating point support?

From: Karri Kaksonen <karri1sipo.fi>
Date: 2004-09-27 17:50:51
I just want to add my comments to the discussion about floating point.
It would be nice to be able to calculate ranges around -1.0 to 1.0 with
decent accuracy for doing matrix stuff.

In the early days I used a routine called FRACMUL quite a lot. Basically
it represents just the 16 bit mantissa.

The way I would like to use it is to define a one as 16384.
This means that I can accurately represent values between -2.0 < x < 2.0
The smallest item you can represent is 0.00006

The fracmul multiplication can already be defined in cc65 as:

int fracmul(int a, int b)
{
  return (long)(a * b) >> 14;
}

But it would be very cool to be able to write:

float a;
a = 0.111;

And this would be translated to
int a;
a = 111 * FRAC_ONE / 1000;      /* FRAC_ONE = 16384 */

I prefer to waste only 16 bits for representing a float in a machine like
the Atari Lynx. The available sprite engine cannot handle a bigger space
anyway.

If you need a larger range than -2 .. 2. You can always treat the second
operand as an int:

float a = 0.111;
int b = 1500;
int c = fracmul(a * b);

expands to (111 * FRAC_ONE / 1000) * 1500 = 166

In my opinion this would be the optimum solution for expanding the cc65
compiler. I admit that you cannot port all programs using floats by
this technique. But most games using floats could be ported with this
technique. The good thing is that we can use + and - from the int-types
directly for the float-type.

--
Regards,

Karri Kaksonen

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Sep 27 17:43:36 2004

This archive was generated by hypermail 2.1.8 : 2004-09-27 17:43:45 CEST