[Gambas-user] Confusion in Data Types

nando nando_f at ...951...
Tue Jun 9 03:23:24 CEST 2009


Float and Double is not as simple an explaination as the Int and others.
You should read a Wiki on floating point storage and issues involving it.
What you're attempting to do is a difficult thing because you're getting
to the limits of float numbers and straddling the edge of NAN and other
wierd things about float that it cannot do.

Floating point numbers have two parts.
Simplistically: One part is an integer which represents the actual digits in binary.
The other is the value of the exponent (binary point and not decimal point).
Together they make up float.  There are values that cannot be properly
represented in float...like the fraction one-third.  If you made a test program
to calculate fractions from integers and then add three 'one-thirds' together, you
won't get 1.00000000000000.... because it is not exactly exact in the last digits.

The easiest test for float is: it better work properly given it's condition
...and move on to something else.

However, good luck.
-Fernando


---------- Original Message -----------
From: KhurramM <kmsuse at ...626...>
To: gambas-user at lists.sourceforge.net
Sent: Mon, 8 Jun 2009 03:50:04 -0700 (PDT)
Subject: [Gambas-user]  Confusion in Data Types

> I am on ubuntu 9.04, x86, 32bit, gambas 2.12. I have some confusion regarding
> the following:
> 
> ----------------------------
> 
> PUBLIC SUB Main()
> 
>    DIM myBoolean AS Boolean
>    DIM myByte AS Byte
>    DIM myShort AS Short
>    DIM N, myInteger AS Integer
>    DIM myLong AS Long
>    DIM mySingle AS Single
>    DIM myFloat AS Float
> 
>    PRINT "RANGES"
>    myByte = 255
>    PRINT "Max value in Byte " & myByte
>    myByte += 1   '  Wraps OK; No BUG
>    PRINT "Min value in Byte " & myByte
> 
>    ' Short  (2-Bytes) is 16 bit; 2^16=65536; half is 32768; ie -32768 to
> 32767
>    myShort = 32767
>    PRINT "Max value in Short " & myShort
>    myShort += 1   '  Wraps OK; No BUG
>    PRINT "Min value in Short " & myShort
> 
>    ' Integer (4-Bytes) 2^bits = 2^32 = 4294967296;
> (4294967296/2=2147483648); -2147483648 to 2147483647
>    myInteger = 2147483647
>    PRINT "Max value in Integer " & myInteger
>    myInteger += 1  '  Wraps OK; No BUG
>    PRINT "Min value in Integer " & myInteger
> 
>    ' Long (8-Bytes) 2^bits = 2^64; -9223372036854775808 to
> 9223372036854775807
>    myLong = 9223372036854775807
>    PRINT "Max value in Long " & myLong
>    myLong += 1  '  Wraps OK; No BUG
>    PRINT "Min value in Long " & myLong
> 
>    ' Single (4-Byte C Float) 1.2e-38 to 3.4e38 
>    mySingle = 3.4e+38
>    PRINT "Max value in Single " & mySingle
>    mySingle += 1 '1e+36    ' Issues
>    PRINT "Min value in Single " & mySingle
> 
>    ' Float (4-Byte C Double) 2.2e-308 to 1.8e308
>    'myFloat = 1.8e+308  BUG: Cant hold this value
>    myFloat = 1.79e+308
>    PRINT "Max value in Float " & myFloat
>    myFloat += 1 ' BUG: DoesNOT Wrap
>    PRINT "Min value in Float " & myFloat
> 
> END
> 
> ----------------------------
> 
> Program Output:
> 
> ----------------------------
> 
> RANGES
> Max value in Byte 255
> Min value in Byte 0
> Max value in Short 32767
> Min value in Short -32768
> Max value in Integer 2147483647
> Min value in Integer -2147483648
> Max value in Long 9223372036854775807
> Min value in Long -9223372036854775808
> Max value in Single 3.399999952144E+38
> Min value in Single 3.399999952144E+38
> Max value in Float 1.79E+308
> Min value in Float 1E+2147483647
> 
> ----------------------------
> 
> I have issue in Single and Float:
> 1. How to overflow the Single and Float?
> 2. Why does the Float not accept the highest value?
> 
> Thanks in advance. :working:
> -- 
> View this message in context:
http://www.nabble.com/Confusion-in-Data-Types-tp23921847p23921847.html
> Sent from the gambas-user mailing list archive at Nabble.com.
> 
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
> looking to deploy the next generation of Solaris that includes the latest 
> innovations from Sun and the OpenSource community. Download a copy and 
> enjoy capabilities such as Networking, Storage and Virtualization. 
> Go to: http://p.sf.net/sfu/opensolaris-get
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list