Home Adobe Substance

Why "-1" is greater than "0" while the numbers are integers?

gnoop
polycounter
Offline / Send Message
gnoop polycounter

And other way around when it's floating point numbers? Could somebody explain it please.

Shouldn't they return same false result?

Replies

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter

    They should. That smells like a bug.

  • gnoop
    Options
    Offline / Send Message
    gnoop polycounter

    Thanks poopipe . I thought I am crazy or missed something big in school.

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter

    I decided to test it


    im getting the same effect when using greater, greater or equal, lower, lower or equal

    -3 is less than -1 though.


    I got into the habit of casting everything to a float before i do any sums cos of the way it affects division in most languages - I find it's generally good practice

  • gnoop
    Options
    Offline / Send Message
    gnoop polycounter

    Yeah, you are right poopipe. I figured out I could just set 1 in input step slider instead of 0.01 and it would be perfectly integer like working.

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter

    Why this was still eating at me is a mystery but I went on a journey through the bowels of stack overflow it emerges that this is entirely possible in C if you don't implement the comparision function in a way that accounts for the negative number (it defaults to doing the comparison in unsigned space if one of the two numbers isn't signed - or something like that).


    still a bug, but it's nice to know where it comes from

  • gnoop
    Options
    Offline / Send Message
    gnoop polycounter

    Here is another weird thing of similar nature probably. If you turn negative integer to float you get something weird but when you try to do it with two integers it's just fine.

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter

    The large number makes sense assuming it's behaving like C cos when you simply remove the sign bit from a signed negative int you get a large positive number.

    Integer2 isn't a conventional data type so I suspect that actually uses floats internally

Sign In or Register to comment.