Advertisement
Lorenc

Math - Include

Sep 16th, 2011
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.59 KB | None | 0 0
  1. /*
  2.  *     
  3.  *                      Math Include by Lorenc_
  4.  *      codename: a_math.inc
  5.  *     
  6.  *      - Getting math equations more easier
  7.  *      - Retreiving math problems     
  8.  *
  9.  *
  10. */
  11.  
  12.  
  13. #define Math.                       lorMath_
  14.  
  15. /*
  16.     native Math.Pi()   
  17.     native Math.Infinite()
  18.     native Math.Highest(...)
  19.     native Math.Add(val, val2)
  20.     native Math.Subtract(val, val2)
  21.     native Math.Divide(val, val2)
  22.     native Math.Multiply(val, val2)
  23.     native Math.SquareRoot(Value)
  24.     native Math.Power(val, val2)
  25.     native Math.Mean(...)
  26.     native Math.Pythagoras( Float: val1, Float: val2, bool: shortside = false )
  27.     native Math.GetMiddlePos(Float: X, Float: Y, Float: X2, Float: Y2, &Float: vX, &Float: vY)
  28.     native Math.RandomEx(min, max)
  29.     native Math.RandomPlayer()
  30.     native Math.IsPositive( num )
  31.     native Math.IsNegative( num )
  32.     native Math.Random3DCoord( Float: minx, Float: miny, Float: minz, Float: maxx, Float: maxy, Float: maxz, &Float: randx, &Float: randy, &Float: randz)
  33. */
  34.  
  35. stock Float: Math.Pi( ) return ( 3.14159265 ); // Correct!
  36. stock Math.Infinite( ) return ( 0x7F800000 ); // Correct!
  37. stock Math.SquareRoot( Float: Val ) return floatsqroot(Val); //Correct but nothing useful... lol.
  38. stock Float: Math.Power( Val, Val2 ) // Correct but not quite useful
  39. {
  40.     new
  41.         Float: Power
  42.     ;
  43.     Power = floatpower(Val, Val2);
  44.     Power = floatround(Power);
  45.     return Power;
  46. }
  47. stock Math.Multiply( val, val2 ) //Correct
  48. {
  49.     new
  50.         aVal
  51.     ;
  52.     aVal = (val1 * val2);
  53.     return aVal;
  54. }
  55. stock Math.Divide( val, val2 ) //Correct
  56. {
  57.     new
  58.         aVal
  59.     ;
  60.     aVal = (val1 / val2);
  61.     return aVal;
  62. }
  63. stock Math.Subtract( val, val2 ) //Correct
  64. {
  65.     new
  66.         aVal
  67.     ;
  68.     aVal = (val1 - val2);
  69.     return aVal;
  70. }
  71. stock Math.Add( val, val2 ) //Correct
  72. {
  73.     new
  74.         aVal
  75.     ;
  76.     aVal = (val1 + val2);
  77.     return aVal;
  78. }
  79. stock Math.Random3DCoord( Float: minx, Float: miny, Float: minz, Float: maxx, Float: maxy, Float: maxz, &Float: randx, &Float: randy, &Float: randz ) // Needs testing
  80. {
  81.     minx = floatround(minx), miny = floatround(miny), minz = floatround(minz);
  82.     maxx = floatround(maxx), maxy = floatround(maxy), maxz = floatround(maxz);
  83.     if(minx > maxx || miny > maxy || minz > maxz) return 0;
  84.     randx = Math.RandomEx(minx,maxx);
  85.     randy = Math.RandomEx(miny,maxy);
  86.     randz = Math.RandomEx(minz,maxz);
  87.     return 1;
  88. }
  89. stock bool: Math.IsNegative( Float: num )
  90. {
  91.     if( num < 0.0 ) return true;
  92.     return false;
  93. }
  94. stock bool: Math.IsPositive( Float: num ) // Correct
  95. {
  96.     if( num >= 0 ) return true;
  97.     return false;
  98. }
  99. stock Math.RandomPlayer() // Correct
  100. {
  101.     new randomplayers[MAX_PLAYERS char], id;
  102.     for(new i; i < MAX_PLAYERS; i++)
  103.     {
  104.         if(IsPlayerConnected(i))
  105.         {
  106.             randomplayers{id} = i;
  107.             id ++;
  108.         }
  109.     }
  110.     if(id == 0) return 0;
  111.     return randomplayers{random(id)};
  112. }
  113. stock Math.RandomEx( min, max ) // Correct
  114. {
  115.     new
  116.         val
  117.     ;
  118.     val = random(max - min) + min;
  119.     return val;
  120. }
  121. stock Math.Pythagoras( Float: val1, Float: val2, bool: shortside = false ) // Correct
  122. {
  123.     new
  124.         Float: cal
  125.     ;
  126.     if(shortside) cal = ((val1 * val1) - (val2 * val2));
  127.     else cal = ((val1 * val1) + (val2 * val2));
  128.     cal = floatsqroot(cal);
  129.     return cal;
  130. }
  131. stock Math.Highest(...) // Correct!
  132. {
  133.     new  
  134.         iArgs = numargs(),
  135.         value
  136.     ;
  137.     for(new i; i < iArgs; i++)
  138.     {
  139.         if(Math.IsNegative(getarg(i))) continue;
  140.         if(getarg(i) > value) value = getarg(i);
  141.     }
  142.     return value;
  143. }
  144. stock Math.Mean(...) // Correct
  145. {
  146.     new  
  147.         iArgs = numargs(),
  148.         value
  149.     ;
  150.     for(new i; i < iArgs; i++) value += getarg(i);
  151.     value = value / iArgs;
  152.     return value;
  153. }
  154. stock Math.GetMiddlePos( Float: X, Float: Y, Float: X2, Float: Y2, &Float: vX, &Float: vY ) // Correct
  155. {
  156.     vX = ( X + X2 ) / 2;
  157.     vY = ( Y + Y2 ) / 2;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement