OsApproxEquals

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Add exemple 1)
Line 9: Line 9:
 
integer osApproxEquals(vector va, vector vb, float margin)<br/>
 
integer osApproxEquals(vector va, vector vb, float margin)<br/>
 
integer osApproxEquals(rotation ra, rotation rb, float margin)
 
integer osApproxEquals(rotation ra, rotation rb, float margin)
|ossl_example=<source lang="lsl">
+
|description=Returns 1 (true) if the quantities or all their components do not differ by the margin value, or 1e-6 (0.000001), if margin is not provided. Returns 0 (false) otherwise.
 +
|ossl_example=
 +
'''Compare two floats'''
 +
<source lang="lsl">
 +
//
 +
// osApproxEquals Script Exemple
 +
// Author: djphil
 +
//
  
...
+
integer switch;
if(osApproxEquals(pos, otherpos, 0.2)) // on Xengine use if(osApproxEquals(pos, otherpos, 0.2) == 1)
+
    llOwnerSay("Positions are almost equal");
+
  
if(osApproxEquals(pos, otherpos)) // on Xengine use if(osApproxEquals(pos, otherpos) == 1)
+
default
    llOwnerSay("Positions are closer than 0.000001 on x y and z");
+
{
 +
    state_entry()
 +
    {
 +
        llSay(PUBLIC_CHANNEL, "Touch to see osApproxEquals usage.");
 +
        llSay(PUBLIC_CHANNEL, "This exemple compare two floats.");
 +
    }
  
...
+
    touch_start(integer number)
 +
    {
 +
        float fa = 1.000000;
 +
        float fb = 1.000001;
 +
 
 +
        if (switch =! switch)
 +
        {
 +
            fb = 1.000002;
 +
        }
 +
 
 +
        llSay(PUBLIC_CHANNEL, "The float \"fa\" value is " + (string)fa);
 +
        llSay(PUBLIC_CHANNEL, "The float \"fb\" value is " + (string)fb);
 +
 
 +
        // On Xengine use if (osApproxEquals(a, b) == TRUE)
 +
        if (osApproxEquals(fa, fb))
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "The values fa and fb are closer than 0.000001 on x, y and z ...");
 +
        }
 +
 
 +
        else
 +
        {
 +
            llSay(PUBLIC_CHANNEL, "The values fa and fb are not closer than 0.000001 on x, y and z ...");
 +
        }
 +
    }
 +
}
 
</source>
 
</source>
|description=Returns 1 (true) if the quantities or all their components do not differ by the margin value, or 1e-6 (0.000001), if margin is not provided. Returns 0 (false) otherwise.
+
|additional_info=Implemented November 20, 2018
|additional_info=Implemented November 20, 2018
+
 
}}
 
}}

Revision as of 11:38, 3 December 2020

integer osApproxEquals(float a, float b)

integer osApproxEquals(vector va, vector vb)
integer osApproxEquals(rotation ra, rotation rb)
integer osApproxEquals(float a, float b, float margin)
integer osApproxEquals(vector va, vector vb, float margin)
integer osApproxEquals(rotation ra, rotation rb, float margin)

Returns 1 (true) if the quantities or all their components do not differ by the margin value, or 1e-6 (0.000001), if margin is not provided. Returns 0 (false) otherwise.
Threat Level This function does not do a threat level check
Permissions Use of this function is always allowed by default
Extra Delay 0 seconds
Example(s)
Compare two floats
//
// osApproxEquals Script Exemple
// Author: djphil
//
 
integer switch;
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch to see osApproxEquals usage.");
        llSay(PUBLIC_CHANNEL, "This exemple compare two floats.");
    }
 
    touch_start(integer number)
    {
        float fa = 1.000000;
        float fb = 1.000001;
 
        if (switch =! switch)
        {
            fb = 1.000002;
        }
 
        llSay(PUBLIC_CHANNEL, "The float \"fa\" value is " + (string)fa);
        llSay(PUBLIC_CHANNEL, "The float \"fb\" value is " + (string)fb);
 
        // On Xengine use if (osApproxEquals(a, b) == TRUE)
        if (osApproxEquals(fa, fb))
        {
            llSay(PUBLIC_CHANNEL, "The values fa and fb are closer than 0.000001 on x, y and z ...");
        }
 
        else
        {
            llSay(PUBLIC_CHANNEL, "The values fa and fb are not closer than 0.000001 on x, y and z ...");
        }
    }
}
Notes
Implemented November 20, 2018


Personal tools
General
About This Wiki