[Gambas-user] Variable overflow questions
user
demosthenesk at ...626...
Fri Nov 5 22:44:39 CET 2010
Thank you VERY much, very nice explanation!
On Fri, 2010-11-05 at 15:00 -0400, nando wrote:
> Here is a visualization (view this email with a fixed width font):
> Regarding your line: DIM iArea AS Single = 1.7014118E+38
> A Single only has about 8 digits of precision so, the number is really this:
> 170,141,180,000,000,000,000,000,000,000,000,000,000.0
> 1.0 +
> =====================================================
> 170,141,180,000,000,000,000,000,000,000,000,000,000.0 =
> ^^^^^^^^^^
> SINGLE only has room for about 8 digits of precision not all 38.
> So, adding 1 means nothing.
> -Fernando
>
> ---------- Original Message -----------
> From: Doriano Blengino <doriano.blengino at ...1909...>
> To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
> Sent: Wed, 03 Nov 2010 10:26:23 +0100
> Subject: Re: [Gambas-user] Variable overflow questions
>
> > user ha scritto:
> > > Hi i check the overflow of variables and there is something i dont
> > > understand.
> > >
> > > My system is
> > >
> > > user at ...2493...:~$ cat /etc/*release*
> > > DISTRIB_ID=Ubuntu
> > > DISTRIB_RELEASE=10.04
> > > DISTRIB_CODENAME=lucid
> > > DISTRIB_DESCRIPTION="Ubuntu 10.04.1 LTS"
> > >
> > > Linux ubuntu-desktop 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16
> > > 19:52:42 UTC 2010 x86_64 GNU/Linux
> > >
> > >
> > >
> > > I have this small code
> > > -----------------------------------
> > > ' Gambas class file
> > > PUBLIC SUB Form_Open()
> > >
> > > DIM bVar AS Boolean = TRUE
> > > DIM iNum AS Byte = 255
> > > DIM iA AS Short = 32767
> > > DIM iRoads AS Integer = 2147483647
> > > DIM iBig AS Long = 9223372036854775807
> > > DIM iArea AS Single = 1.7014118E+38
> > > DIM fPi AS Float = 8.98846567431105E+307
> > >
> > > bVar += 1
> > > iNum += 1
> > > iA += 1
> > > iRoads += 1
> > > iBig += 1
> > > iArea += 1
> > > fPi += 1
> > >
> > > PRINT bVar
> > > PRINT iNum
> > > PRINT iA
> > > PRINT iRoads
> > > PRINT iBig
> > > PRINT iArea
> > > PRINT fPi
> > >
> > > END
> > > -----------------------------------
> > >
> > > And i get the following result
> > >
> > > False
> > > 0
> > > -32768
> > > -2147483648
> > > -9223372036854775808
> > > 1.701411834605E+38
> > > 8.988465674311E+307
> > >
> > >
> > > My question is why the Single and Float do not overflow?
> > >
> > Because they should not overflow, I think. "Real" numbers (in the IT
> > sense: "float" if you prefer ) are not discrete numbers, they have a
> > limited precision; a single bit pattern in a float corresponds to
> > infinite numbers in the real world. When you add a very small quantity
> > to a float (and "1", compared to 1E+38, is very small), you simply tell
> > it to store a different number, which has the same bit representation.
> > If a float would overflow, it would cease its main reason to exist: in
> > most situations you *do* want it to behave so. You could add a bigger
> > number to make it overflow: you should add a number big enough to fall
> > in the precision bits of the mantissa. A normal float has perhaps 6/7
> > digits of precision; to choose a comparable a number, you should choose
> > something like 1E+31 (this "1" falls in the digits of precision of
> > 1E+38). But! Even in that case, the number should not overflow, but
> > raise an error (overflow error). This last thing depends on
> > implementation of the floating point by the host computer.
> >
> > Regards,
> > Doriano
> >
> > ------------------------------------------------------------------------------
> > Achieve Improved Network Security with IP and DNS Reputation.
> > Defend against bad network traffic, including botnets, malware,
> > phishing sites, and compromised hosts - saving your company time,
> > money, and embarrassment. Learn More!
> > http://p.sf.net/sfu/hpdev2dev-nov
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------- End of Original Message -------
>
>
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> 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