Jump to content

Tuu Munz

Resident
  • Posts

    11
  • Joined

  • Last visited

Posts posted by Tuu Munz

  1. 11 hours ago, steph Arnott said:

    Reality check in regards to the OPs statement. This is SL and  LSL does not need to be stupidly accurate. Simply chop off the end to return a three decimal  float.

    You are right. There sure are many ways to handle this feature. But to use them, you have to be aware about it.

    And - shame to me - I haven't been. May be because I have under my years in SL wrote only simple scripts - switching lights on/off, changing colours and textures of prims, playing whit particles for my own fun, making simple menus, etc.

    But recently I have been playing with one opensource script and found out, that sometimes it does what it should do and sometimes doesn't. When I looked it closer, it seemed to me, that logic there were quite right, but that the aberration there must have something to do with the way LSL handles floats. I could fix the script so that I'm happy with it. But as I am curious person, I liked to know, why it worked as it did. Now I know. 😊

  2. Thank you all very much for comments!

    2 hours ago, Nova Convair said:

    This is expected behaviour !!!

    A decimal floating point number like 0.1 or 1.0 or whatever is stored and computed in a binary format.

    And a 0.1 in decimal notation can not be converted into a binary format without using an infinite number of digits. So the number is cut off after using 32 or 64 bits or whatever float format is used. If you caculate with this number it is NOT a 0.1 it's just very close to a 0.1

    If you compare 2 different calculations it's very probable that they are NOT equal even if they should.
    That's why I never compare 2 floats for equality - I compare if the difference is less than 0.0001 for example or whatever precision I need in this specific case. 

     

    2 hours ago, Madelaine McMasters said:

    Remember that computers are binary, not decimal (there were decimal computers long ago). In binary floating point, the decimal number 0.1 is irrational. Like PI,  or 1/3 in decimal, no matter how many digits/bits you list, you're still not right. If you start out with irrational truncation errors, subsequent calculations with their inherent rounding will only make things worse. As Nova says, you must treat floating point numbers as approximations and you must compare them with an appropriate error band. And do make sure that your error band is not smaller than your rounding error, which depends on the floating point precision and the number and nature of math operations you do prior to making your comparison.

    https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/

    So this is a feature.
    (Allways nice to be today wiser than yesterday 😋.)

  3. LSL is calculating:

    default
    {
        touch_start(integer total_number)
        {
            float X = 0.10;
            float Y = 0.00;
    
            Y += X;
            Y += X;
            Y += -X;
            Y += -X;
              
            llOwnerSay("Y is " + (string)Y);
            
            if (Y > 0.000000)
            {
                llOwnerSay("Y is greater than 0.000000");
            }
            else if (Y == 0.000000)
            {
                llOwnerSay("Y is equal to 0.000000");
            }
            else if (Y < 0.000000)
            {
                llOwnerSay("Y is less than 0.000000");
            }
            else
            {
                llOwnerSay("Sorry, I don't know.");  
            }        
        }
    }


    and gives response:
    [04:19] Object: Y is 0.000000
    [04:19] Object: Y is equal to 0.00000

    Ok.

    But when LSL is calculating:

    default
    {
        touch_start(integer total_number)
        {
            float X = 0.10;
            float Y = 0.00;
    
            Y += X;
            Y += X;
            Y += X;
            Y += -X;
            Y += -X;
            Y += -X;
            llOwnerSay("Y is " + (string)Y);
            
            if (Y > 0.000000)
            {
                llOwnerSay("Y is greater than 0.000000");
            }
            else if (Y == 0.000000)
            {
                llOwnerSay("Y is equal to 0.000000");
            }
            else if (Y < 0.000000)
            {
                llOwnerSay("Y is less than 0.000000");
            }
            else
            {
                llOwnerSay("Sorry, I don't know.");  
            }        
        }
    }


    is response:
    [04:20] Object: Y is 0.000000
    [04:20] Object: Y is greater than 0.000000

    Is this a known bug (which I haven't known), or is this a feature?
    Or am I stupid?

×
×
  • Create New...