[Gambas-user] numerical error in Gambas??

Jesper Holm jholm at ...381...
Wed Mar 31 20:43:06 CEST 2004


Hello again,

I have not have any response on my problem. Could anyone please confirm that 
Gambas DO indeed work on multplication/division?

I have a program running which is supposed to simulate a nonlinear laser 
cavity, so I really hope the problem is with my computer/compiler or 
something.

Please try to:

Start a new projet.
Make a startup-module, with the code:

	PRINT 1.663 * (1 / 1.663)

and compile and run. On my computer Gambas prints 0.1, where I am supposed to 
get a 1 ?!?!

I know the parenthesis is redundant, but my expression was (considerably) more 
complicated, and it should work with the parenthesis.

The funny thing is that when I change 1.663 to 1.664 I get the correct result. 
Varying the number a bit in a FOR-loop shows sporadic errors.

Can anyone reproduce these results???

Jesper

On Monday 29 March 2004 14:27, jholm at ...381... wrote:
> Hi everyone,
>
> I have a rather peculiar problem when I compile the following in Gambas:
>
> PUBLIC SUB Main()
>    DIM i AS Float
>
>    FOR i = 1.66 TO 1.70 STEP 0.001
>      PRINT i*(1.0/i)
>    NEXT
>
> END
>
>
> I get "0.1" values for some of the i values, which is obviously wrong.
>
> By doing the same in C++ (and compiling with g++):
>
>
> #include <iostream>
> using namespace std;
>
> int main(void)
> { for (double i=1.66; i<1.7;i +=0.001){ cout << i*(1/i); };
>   return 0; }
>
> I get the correct stream of 1's.
>
> I have compiled Gambas directly from source, with no problems in the
> configure script (but no db components are compiled).
>
> Is this just my machine? or have I totally misunderstood that division
> operator?
>
> Jesper
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user




More information about the User mailing list