"+=" inconsistency.

About Monkey 2 Forums Monkey 2 Development "+=" inconsistency.

This topic contains 5 replies, has 3 voices, and was last updated by  Danilo 1 year, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8445

    Jesse
    Participant

    when adding a float to an integer with “+=” gives odd results:

    [/crayon]

    This should print 0 for both but it displays some odd numbers and inconsistent at that.

    It might be an issue for OSX Only.

    I already posted it to GitHub. This is just in case somebody runs into this problem as well.

    #8448

    TomToad
    Participant

    I get 11598408 for both on Windows 10.  I think it has to do with the Float to Int conversion done on the .1. If you use 0.1 instead or define y as a float, then you get correct results.

    #8449

    Jesse
    Participant

    I get inconsistent results every time I run it:
    this:
    -1718160848
    -1718160848
    then this:
    -1842821072
    -1842821072
    then this:
    -1145541584
    -1145541584

    etc..

    The reason I run into this problem was because I was trying to get some integer values from a Rnd operation. and I couldn’t figure out why I was getting this strange values. I was getting this by adding the random float value to an integer.

    #8450

    Danilo
    Participant

    It has nothing to do with ‘+=’, it is that ‘.1’ is not correctly converted to integer.
    The result is a random (uninitialized) number:

    For the loop it displays the same number 5 times, because it is only generated once.
    For the Print statements, each of the 5 assignments result in different uninitialzed/random numbers.

    Output:

    The generated C++ code has the wrong numbers directly implemented (hard coded):

    #8453

    Jesse
    Participant

    I see. But strange still.
    I was going to post the exact code but I have since modified it and can’t exactly remember how I had it that it was giving me wrong values with a Rnd assignment to an integer. I tried to duplicate it but can’t do it anymore. It wasn’t a constant value.
    Oh well it will probably will creep in some other project again.

    #8454

    Danilo
    Participant

    > But strange still.

    Of course still a bug that needs to be looked at by Mark.
    Works with ‘0.1’, but with ‘.1’ there is a problem somewhere
    in the semantic process, automatic type conversion, or
    code generation.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.