Difference between revisions of "Max"

From Second Life Wiki
Jump to navigation Jump to search
m (typo: mix -> min in example)
m (<lsl> tag to <source>)
 
Line 12: Line 12:
See also: [[Min]]
See also: [[Min]]
|examples=
|examples=
<lsl>float value = max(10,20); //value == 20</lsl>
<source lang="lsl2">float value = max(10,20); //value == 20</source>
|spec=<lsl>float max(float x, float y) {
|spec=<source lang="lsl2">float max(float x, float y) {
     if( y > x ) return y;
     if( y > x ) return y;
     return x;
     return x;
}</lsl>
}</source>
|helpers
|helpers
|also_functions
|also_functions
|also_events
|also_events
|also_tests=
|also_tests=
<lsl>// Max and Min Functions and Unit Tests
<source lang="lsl2">// Max and Min Functions and Unit Tests
float max(float x, float y) {
float max(float x, float y) {
     if( y > x ) return y;
     if( y > x ) return y;
Line 70: Line 70:
         ix=-0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
         ix=-0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
     }
     }
}</lsl>
}</source>
|also_articles
|also_articles
|location
|location

Latest revision as of 17:16, 24 January 2015

Summary

Function: float max( float x, float y );

Returns the greater of two arbitrary values
Returns a float

• float x
• float y

If values x and y are equal, returns x

See also: Min

Specification

float max(float x, float y) {
    if( y > x ) return y;
    return x;
}

Examples

float value = max(10,20); //value == 20

Deep Notes

Tests

// Max and Min Functions and Unit Tests
float max(float x, float y) {
    if( y > x ) return y;
    return x;
}

float min(float x, float y) {
    if( y < x ) return y;
    return x;
}

// Emilie (Hermit Barber in World)
// Creative Commons: Attribution, Share-alike, Non Commercial
// Copy the above functions to your program - the following code is merely a set of unit tests
say(string f, float x,float y, float z)
{
    llOwnerSay("Testing " + f + " with input X: " + (string) x +  " Input Y: " + (string) y + "Resulting in: " + (string) z);
}

default
{
    state_entry()
    {
        string test = "MAX";
        float ix = 0;
        float iy = 0;
        float iz = 0;
        say(test,ix,iy,max(ix,iy));
        ix=100;iy=100;say(test,ix,iy,max(ix,iy));
        ix=-100;iy=100;say(test,ix,iy,max(ix,iy));
        ix=100;iy=-100;say(test,ix,iy,max(ix,iy));
        ix=-100;iy=-100;say(test,ix,iy,max(ix,iy));
        ix=-0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
        ix=0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
        ix=-0.001;iy=0.00001;say(test,ix,iy,max(ix,iy));
        ix=0.001;iy=-0.00001;say(test,ix,iy,max(ix,iy));
        ix=-0.001;iy=-0.00001;say(test,ix,iy,max(ix,iy));
        
        test = "MIN";
        say(test,ix,iy,min(ix,iy));
        ix=100;iy=100;say(test,ix,iy,min(ix,iy));
        ix=-100;iy=100;say(test,ix,iy,min(ix,iy));
        ix=100;iy=-100;say(test,ix,iy,min(ix,iy));
        ix=-100;iy=-100;say(test,ix,iy,min(ix,iy));
        ix=0.001;iy=0.00001;say(test,ix,iy,min(ix,iy));
        ix=-0.001;iy=0.00001;say(test,ix,iy,min(ix,iy));
        ix=0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
        ix=-0.001;iy=-0.00001;say(test,ix,iy,min(ix,iy));
    }
}

Signature