5 #if defined _float_included
8 #define _float_included
12 * All the trigonometric functions take in or return its values in RADIANS.
13 * Use DegToRad or RadToDeg stocks to convert the radix units.
16 /* Different methods of rounding */
17 enum floatround_method
26 * Converts an integer into a floating point value.
28 * @param value Integer to convert.
29 * @return Floating point value.
31 native Float:float(value);
34 * Converts a string into a floating point value.
36 * @param str String to convert.
37 * @return Converted floating point number.
39 native Float:FloatStr(const String:str[]);
42 * Multiplies two floats together.
44 * @param oper1 First value.
45 * @param oper2 Second value.
46 * @return oper1*oper2.
48 native Float:FloatMul(Float:oper1, Float:oper2);
51 * Divides the dividend by the divisor.
53 * @param dividend First value.
54 * @param divisor Second value.
55 * @return dividend/divisor.
57 native Float:FloatDiv(Float:dividend, Float:divisor);
60 * Adds two floats together.
62 * @param oper1 First value.
63 * @param oper2 Second value.
64 * @return oper1+oper2.
66 native Float:FloatAdd(Float:oper1, Float:oper2);
69 * Subtracts oper2 from oper1.
71 * @param oper1 First value.
72 * @param oper2 Second value.
73 * @return oper1-oper2.
75 native Float:FloatSub(Float:oper1, Float:oper2);
78 * Returns the decimal part of a float.
80 * @param value Input value.
81 * @return Decimal part.
83 native Float:FloatFraction(Float:value);
86 * Rounds a float into an integer number.
88 * @param value Input value to be rounded.
89 * @param method Rounding method to use.
90 * @return Rounded value.
92 native FloatRound(Float:value, floatround_method:method=floatround_round);
95 * Compares two floats.
97 * @param fOne First value.
98 * @param fTwo Second value.
99 * @return Returns 1 if the first argument is greater than the second argument.
100 * Returns -1 if the first argument is smaller than the second argument.
101 * Returns 0 if both arguments are equal.
103 native FloatCompare(Float:fOne, Float:fTwo);
106 * Returns the square root of the input value, equivalent to floatpower(value, 0.5).
108 * @param value Input value.
109 * @return Square root of the value.
111 native Float:SquareRoot(Float:value);
114 * Returns the value raised to the power of the exponent.
116 * @param value Value to be raised.
117 * @param exponent Value to raise the base.
118 * @return value^exponent.
120 native Float:Pow(Float:value, Float:exponent);
123 * Returns the value of raising the input by e.
125 * @param value Input value.
126 * @return exp(value).
128 native Float:Exponential(Float:value);
131 * Returns the logarithm of any base specified.
133 * @param value Input value.
134 * @param base Logarithm base to use, default is 10.
135 * @return log(value)/log(base).
137 native Float:Logarithm(Float:value, Float:base=10.0);
140 * Returns the sine of the argument.
142 * @param value Input value in radians.
143 * @return sin(value).
145 native Float:Sine(Float:value);
148 * Returns the cosine of the argument.
150 * @param value Input value in radians.
151 * @return cos(value).
153 native Float:Cosine(Float:value);
156 * Returns the tangent of the argument.
158 * @param value Input value in radians.
159 * @return tan(value).
161 native Float:Tangent(Float:value);
164 * Returns the absolute value.
166 * @param value Input value.
167 * @return abs(value).
169 native Float:FloatAbs(Float:value);
172 * Returns the arctangent of the input value.
174 * @param angle Input value.
175 * @return atan(value) in radians.
177 native Float:ArcTangent(Float:angle);
180 * Returns the arccosine of the input value.
182 * @param angle Input value.
183 * @return acos(value) in radians.
185 native Float:ArcCosine(Float:angle);
188 * Returns the arcsine of the input value.
190 * @param angle Input value.
191 * @return asin(value) in radians.
193 native Float:ArcSine(Float:angle);
196 * Returns the arctangent2 of the input values.
198 * @param x Horizontal value.
199 * @param y Vertical value.
200 * @return atan2(value) in radians.
202 native Float:ArcTangent2(Float:x, Float:y);
205 * User defined operators.
208 #pragma rational Float
210 native Float:operator*(Float:oper1, Float:oper2) = FloatMul;
211 native Float:operator/(Float:oper1, Float:oper2) = FloatDiv;
212 native Float:operator+(Float:oper1, Float:oper2) = FloatAdd;
213 native Float:operator-(Float:oper1, Float:oper2) = FloatSub;
215 stock Float:operator++(Float:oper)
218 stock Float:operator--(Float:oper)
221 stock Float:operator-(Float:oper)
222 return oper^Float:((-1)^((-1)/2)); /* IEEE values are sign/magnitude */
224 stock Float:operator*(Float:oper1, oper2)
225 return FloatMul(oper1, float(oper2)); /* "*" is commutative */
227 stock Float:operator/(Float:oper1, oper2)
228 return FloatDiv(oper1, float(oper2));
230 stock Float:operator/(oper1, Float:oper2)
231 return FloatDiv(float(oper1), oper2);
233 stock Float:operator+(Float:oper1, oper2)
234 return FloatAdd(oper1, float(oper2)); /* "+" is commutative */
236 stock Float:operator-(Float:oper1, oper2)
237 return FloatSub(oper1, float(oper2));
239 stock Float:operator-(oper1, Float:oper2)
240 return FloatSub(float(oper1), oper2);
242 stock bool:operator==(Float:oper1, Float:oper2)
243 return FloatCompare(oper1, oper2) == 0;
245 stock bool:operator==(Float:oper1, oper2)
246 return FloatCompare(oper1, float(oper2)) == 0; /* "==" is commutative */
248 stock bool:operator!=(Float:oper1, Float:oper2)
249 return FloatCompare(oper1, oper2) != 0;
251 stock bool:operator!=(Float:oper1, oper2)
252 return FloatCompare(oper1, float(oper2)) != 0; /* "==" is commutative */
254 stock bool:operator>(Float:oper1, Float:oper2)
255 return FloatCompare(oper1, oper2) > 0;
257 stock bool:operator>(Float:oper1, oper2)
258 return FloatCompare(oper1, float(oper2)) > 0;
260 stock bool:operator>(oper1, Float:oper2)
261 return FloatCompare(float(oper1), oper2) > 0;
263 stock bool:operator>=(Float:oper1, Float:oper2)
264 return FloatCompare(oper1, oper2) >= 0;
266 stock bool:operator>=(Float:oper1, oper2)
267 return FloatCompare(oper1, float(oper2)) >= 0;
269 stock bool:operator>=(oper1, Float:oper2)
270 return FloatCompare(float(oper1), oper2) >= 0;
272 stock bool:operator<(Float:oper1, Float:oper2)
273 return FloatCompare(oper1, oper2) < 0;
275 stock bool:operator<(Float:oper1, oper2)
276 return FloatCompare(oper1, float(oper2)) < 0;
278 stock bool:operator<(oper1, Float:oper2)
279 return FloatCompare(float(oper1), oper2) < 0;
281 stock bool:operator<=(Float:oper1, Float:oper2)
282 return FloatCompare(oper1, oper2) <= 0;
284 stock bool:operator<=(Float:oper1, oper2)
285 return FloatCompare(oper1, float(oper2)) <= 0;
287 stock bool:operator<=(oper1, Float:oper2)
288 return FloatCompare(float(oper1), oper2) <= 0;
290 stock bool:operator!(Float:oper)
291 return (_:oper & ((-1)/2)) == 0; /* -1 = all bits to 1; /2 = remove most significant bit (sign)
292 works on both 32bit and 64bit systems; no constant required */
295 * Forbidden operators.
298 forward operator%(Float:oper1, Float:oper2);
299 forward operator%(Float:oper1, oper2);
300 forward operator%(oper1, Float:oper2);
302 #define FLOAT_PI 3.1415926535897932384626433832795
304 stock Float:DegToRad(Float:angle)
306 return (angle*FLOAT_PI)/180;
309 stock Float:RadToDeg(Float:angle)
311 return (angle*180)/FLOAT_PI;