[Gambas-user] Calculation Bug?

timothy timothy.marshal-nichols at ...247...
Tue Nov 28 16:45:50 CET 2006


> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
> bounces at lists.sourceforge.net] On Behalf Of R. Stormo
> Sent: 27 November 2006 20:52
> To: gambas-user at lists.sourceforge.net
> Subject: [Gambas-user] Calculation Bug?
> 
> 
> I'm doing a small calculation for a CDI box to a 4 wheel bike. And
when I
> putting the function togheter it does not calculate the right values
> according to the calculator.
> 
> >From Debug.
> Dim fTmp1 as Float
> fTmp1 =  618 * 2 * 60 * 1000000 / (618 * 2) / 360 =2574.51449119022
> 
> 
> The calculator gives the value
> 
> 166666,666666667
> 
> Spreadsheet gives
> 166666,666666667
> 
> So there must be something wrong in gambas when calculation is done.
> 
> Because if I take one zero from the 1000000 it gives me a total
different
> value
> Dim fTmp1 as Float
> fTmp1 =  618 * 2 * 60 * 100000 / (618 * 2) / 360 =-2638.29241280115
> 
> Should have been 16666,6666666667
> 
> 
> 
> Regards R. Stormo
> 
>   My Gambas Community  http://gambasforum.tk
> 
> 


This is a common problem with programming language data types - not just
Gambas. The problem is the max size of an integer is 2,147,483,649. But
=  618 * 2 * 60 * 100000 = 74,160,000,000. You can get the right result
by using a Long or Float data types. This shows what I mean:

PRINT CLng(618) * CLng(2) * CLng(60) * CLng(100000) / (CLng(618) *
CLng(2)) / CLng(360)

Thought there are better ways of programming the calculation.

Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>








More information about the User mailing list