Announcement

Collapse
No announcement yet.

Strange behaviour with "Double" type

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Eddy Van Esch
    replied
    Originally posted by Alex Chambers View Post
    Why the complier doesn't already know it's type Double, I don't know! I just declared it!!!
    The compiler first converts the ascii string "1.0005" to a binary floating point number.
    If you don't specify "1.0005#", the compiler makes this a single precision float (SINGLE).
    After that, it stores your SINGLE 1.0005 into a variable kk, which is a DOUBLE.
    With the conversion from ascii string "1.0005" to a SINGLE, a rounding error occurs, due to the limited precision of a SINGLE .

    Kind regards

    Leave a comment:


  • Alex Chambers
    replied
    Thanks.

    Why the complier doesn't already know it's type Double, I don't know! I just declared it!!!

    Anyhow, this only seems to be the case for Doubles - Singles and Longs are fine without the type specifier.

    Leave a comment:


  • Petr Schreiber jr
    replied
    Hi,

    I am afraid you need to help compiler a bit by adding "type specifier".
    So just change:
    Code:
    kk = 1.0005
    to
    Code:
    kk = 1.0005#
    # is symbol for double precision.


    Bye,
    Petr

    Leave a comment:


  • Alex Chambers
    started a topic Strange behaviour with "Double" type

    Strange behaviour with "Double" type

    Hello,

    I'm finding strange things with the double float type:

    LOCAL kk AS DOUBLE

    kk = 1.0005
    MSGBOX(STR$(kk))


    This gives a msgbox of "1.00049996376038" !!!

    ?????

    It should be "1.0005"

    Why is this happening and can I correct the behaviour? I'm using PB/Win 8.0


    Thanks, alex
Working...
X