[Gambas-user] numerical error in Gambas??

ron ronstk at ...239...
Thu Apr 1 19:18:55 CEST 2004


On Thursday 01 April 2004 18:32, Benoit Minisini wrote:
> On Thursday 01 April 2004 00:08, Jesper Holm wrote:
> > Hi Benoit,
> >
 snip
>
> You are facing problems with floating point numbers common to every
> program. Never compare two floating point numbers, because even if Gambas
> displays ('will' when the previous bug is fixed) 1, the number could be not
> exactly equal to 1. The difference is too small to be displayed.
>

snip

> Yes, or use Round(): IF Round((a * (1 / a)) - 1, -10) = 0 THEN ...
>
> Regards,

This does remember me a method I used.
On a Z80 CPU there is no Floating Point at all.
I want to draw a circle on the screen, so what can i do?

The Pitagoras way with z=sqr(x^2 + y^2) could not be used
because I had no idea to get the SQR() in machine language.
Then only the way with Sin lookup was the way to go.

Simple multiply the floating point with 2^8 (x 256), here the integer
x and y axis. 
i.e. 10.25 in binary way 1010.01b will be 101001000000b

The Sin lookup table was the fractional part simple also multiplied 
by 2^8 (x 256) in  for 90 degrees. I belive it was in 90 bytes, forgotten that 
and were calculated by a basic program.
I know this resolution is not so big but with 32kbyte workspace?

Then I did the multiply and divide on a integers and for the
actual points and to use divide it by 2^8 (/256)  to draw the circle.
They were nice and quick drawn. The good old day's :=)

For your case you could convert the FP by multiply them with 
10^digits_behind you need and put them in a integer.
In this way the comparasion problems as mentioned do not exist.
To use the result you must always divide them of course by the same
10^digits_behind for human readable and realistic value to display.

It is a trick but can be handy in these cases

Ron
  




More information about the User mailing list