Difference between revisions of "Max"

From Second Life Wiki
Jump to navigation Jump to search
m
(by posting you agreed they are under an CC-by-sa license (hard to assert non-commercial); I rewrote internals to void any copyright claim (not really long enough to assert copyright anyway))
Line 13: Line 13:
|examples=
|examples=
<lsl>float value = max(10,20); //value == 20</lsl>
<lsl>float value = max(10,20); //value == 20</lsl>
|spec=<lsl>float max(float x, float y)
|spec=<lsl>float max(float x, float y) {
{
     if( y > x ) return y;
     return ( ( llAbs( x >= y ) ) * x ) + ( ( llAbs( x<y ) ) * y );
    return x;
}</lsl>
}</lsl>
|helpers
|helpers
Line 22: Line 22:
|also_tests=
|also_tests=
<lsl>// Max and Min Functions and Unit Tests
<lsl>// Max and Min Functions and Unit Tests
// Emilie (Hermit Barber in World)
float max(float x, float y) {
// Creative Commons: Attribution, Share-alike, Non Commecial
     if( y > x ) return y;
 
    return x;
float Max(float x,float y)
{
     return ( ( llAbs( x >= y ) ) * x ) + ( ( llAbs( x<y ) ) * y );
}
}


float Min(float x,float y)
float mix(float x, float y) {
{
     if( y < x ) return y;
     return ( ( llAbs( x >= y ) ) * y ) + ( ( llAbs( x<y ) ) * x );
    return x;
}
}


// Copy the above functions to your program - the balance is mereley a set of unit tests
// 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)
say(string f, float x,float y, float z)
{
{
Line 50: Line 48:
         float iy = 0;
         float iy = 0;
         float iz = 0;
         float iz = 0;
         say(test,ix,iy,Max(ix,iy));
         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=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));
         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";
         test = "MIN";
         say(test,ix,iy,Min(ix,iy));
         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=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));
         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));
     }
     }
}</lsl>
}</lsl>

Revision as of 01:14, 1 November 2008

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

<lsl>float max(float x, float y) {

   if( y > x ) return y;
   return x;

}</lsl>

Examples

<lsl>float value = max(10,20); //value == 20</lsl>

Deep Notes

Tests

<lsl>// Max and Min Functions and Unit Tests float max(float x, float y) { if( y > x ) return y; return x; } float mix(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)); } }</lsl>

Signature