SAMP Gitlab CI Test
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.7 KiB

5 years ago
  1. /* Float arithmetic
  2. *
  3. * (c) Copyright 1999, Artran, Inc.
  4. * Written by Greg Garner (gmg@artran.com)
  5. * Modified in March 2001 to include user defined
  6. * operators for the floating point functions.
  7. *
  8. * This file is provided as is (no warranties).
  9. */
  10. #if defined _Float_included
  11. #endinput
  12. #endif
  13. #define _Float_included
  14. #pragma library Float
  15. /* Different methods of rounding */
  16. enum floatround_method {
  17. floatround_round,
  18. floatround_floor,
  19. floatround_ceil,
  20. floatround_tozero,
  21. floatround_unbiased
  22. }
  23. enum anglemode {
  24. radian,
  25. degrees,
  26. grades
  27. }
  28. /**************************************************/
  29. /* Convert an integer into a floating point value */
  30. native Float:float(value);
  31. /**************************************************/
  32. /* Convert a string into a floating point value */
  33. native Float:floatstr(const string[]);
  34. /**************************************************/
  35. /* Multiple two floats together */
  36. native Float:floatmul(Float:oper1, Float:oper2);
  37. /**************************************************/
  38. /* Divide the dividend float by the divisor float */
  39. native Float:floatdiv(Float:dividend, Float:divisor);
  40. /**************************************************/
  41. /* Add two floats together */
  42. native Float:floatadd(Float:oper1, Float:oper2);
  43. /**************************************************/
  44. /* Subtract oper2 float from oper1 float */
  45. native Float:floatsub(Float:oper1, Float:oper2);
  46. /**************************************************/
  47. /* Return the fractional part of a float */
  48. native Float:floatfract(Float:value);
  49. /**************************************************/
  50. /* Round a float into a integer value */
  51. native floatround(Float:value, floatround_method:method=floatround_round);
  52. /**************************************************/
  53. /* Compare two integers. If the two elements are equal, return 0.
  54. If the first argument is greater than the second argument, return 1,
  55. If the first argument is less than the second argument, return -1. */
  56. native floatcmp(Float:oper1, Float:oper2);
  57. /**************************************************/
  58. /* Return the square root of the input value, same as floatpower(value, 0.5) */
  59. native Float:floatsqroot(Float:value);
  60. /**************************************************/
  61. /* Return the value raised to the power of the exponent */
  62. native Float:floatpower(Float:value, Float:exponent);
  63. /**************************************************/
  64. /* Return the logarithm */
  65. native Float:floatlog(Float:value, Float:base=10.0);
  66. /**************************************************/
  67. /* Return the sine, cosine or tangent. The input angle may be in radian,
  68. degrees or grades. */
  69. native Float:floatsin(Float:value, anglemode:mode=radian);
  70. native Float:floatcos(Float:value, anglemode:mode=radian);
  71. native Float:floattan(Float:value, anglemode:mode=radian);
  72. /**************************************************/
  73. /* Return the absolute value */
  74. native Float:floatabs(Float:value);
  75. /**************************************************/
  76. #pragma rational Float
  77. /* user defined operators */
  78. native Float:operator*(Float:oper1, Float:oper2) = floatmul;
  79. native Float:operator/(Float:oper1, Float:oper2) = floatdiv;
  80. native Float:operator+(Float:oper1, Float:oper2) = floatadd;
  81. native Float:operator-(Float:oper1, Float:oper2) = floatsub;
  82. native Float:operator=(oper) = float;
  83. stock Float:operator++(Float:oper)
  84. return oper+1.0;
  85. stock Float:operator--(Float:oper)
  86. return oper-1.0;
  87. stock Float:operator-(Float:oper)
  88. return oper^Float:cellmin; /* IEEE values are sign/magnitude */
  89. stock Float:operator*(Float:oper1, oper2)
  90. return floatmul(oper1, float(oper2)); /* "*" is commutative */
  91. stock Float:operator/(Float:oper1, oper2)
  92. return floatdiv(oper1, float(oper2));
  93. stock Float:operator/(oper1, Float:oper2)
  94. return floatdiv(float(oper1), oper2);
  95. stock Float:operator+(Float:oper1, oper2)
  96. return floatadd(oper1, float(oper2)); /* "+" is commutative */
  97. stock Float:operator-(Float:oper1, oper2)
  98. return floatsub(oper1, float(oper2));
  99. stock Float:operator-(oper1, Float:oper2)
  100. return floatsub(float(oper1), oper2);
  101. stock bool:operator==(Float:oper1, Float:oper2)
  102. return floatcmp(oper1, oper2) == 0;
  103. stock bool:operator==(Float:oper1, oper2)
  104. return floatcmp(oper1, float(oper2)) == 0; /* "==" is commutative */
  105. stock bool:operator!=(Float:oper1, Float:oper2)
  106. return floatcmp(oper1, oper2) != 0;
  107. stock bool:operator!=(Float:oper1, oper2)
  108. return floatcmp(oper1, float(oper2)) != 0; /* "!=" is commutative */
  109. stock bool:operator>(Float:oper1, Float:oper2)
  110. return floatcmp(oper1, oper2) > 0;
  111. stock bool:operator>(Float:oper1, oper2)
  112. return floatcmp(oper1, float(oper2)) > 0;
  113. stock bool:operator>(oper1, Float:oper2)
  114. return floatcmp(float(oper1), oper2) > 0;
  115. stock bool:operator>=(Float:oper1, Float:oper2)
  116. return floatcmp(oper1, oper2) >= 0;
  117. stock bool:operator>=(Float:oper1, oper2)
  118. return floatcmp(oper1, float(oper2)) >= 0;
  119. stock bool:operator>=(oper1, Float:oper2)
  120. return floatcmp(float(oper1), oper2) >= 0;
  121. stock bool:operator<(Float:oper1, Float:oper2)
  122. return floatcmp(oper1, oper2) < 0;
  123. stock bool:operator<(Float:oper1, oper2)
  124. return floatcmp(oper1, float(oper2)) < 0;
  125. stock bool:operator<(oper1, Float:oper2)
  126. return floatcmp(float(oper1), oper2) < 0;
  127. stock bool:operator<=(Float:oper1, Float:oper2)
  128. return floatcmp(oper1, oper2) <= 0;
  129. stock bool:operator<=(Float:oper1, oper2)
  130. return floatcmp(oper1, float(oper2)) <= 0;
  131. stock bool:operator<=(oper1, Float:oper2)
  132. return floatcmp(float(oper1), oper2) <= 0;
  133. stock bool:operator!(Float:oper)
  134. return (_:oper & cellmax) == 0;
  135. /* forbidden operations */
  136. forward operator%(Float:oper1, Float:oper2);
  137. forward operator%(Float:oper1, oper2);
  138. forward operator%(oper1, Float:oper2);