Float and Double image rotation problem

About Monkey 2 Forums Monkey 2 Programming Help Float and Double image rotation problem

This topic contains 2 replies, has 2 voices, and was last updated by  Pakz 2 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5732

    Pakz
    Participant

    When I use doubles for the rotation variable and the rotation modification variable the behaviour is like I want it to be, but when I change them to float the behaviour seems to be different. In one direction it does not rotate at all.

    What can be the problem?

     

    #5735

    arpie
    Participant

    This is because TwoPi is a Double.

    On line 71, if rot < 0, rot is set to TwoPi (implicit cast from Double to Float) but on line 72 you then compare a Float with a Double.  It looks like they are being implicitly cast to Doubles before being compared and so rot is rounded to be slightly larger than TwoPi… and gets set back to zero.

    Try changing line 72 to :

    If i.rot > Cast<Float>(TwoPi) Then i.rot=0

    Or define your own variable TwoPiF (or whatever) as a Float if you don’t like using an explicit cast.

    #5736

    Pakz
    Participant

    Thank you ! That solved it.

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

You must be logged in to reply to this topic.