/* Float arithmetic * * (c) Copyright 1999, Artran, Inc. * Written by Greg Garner (gmg@artran.com) * Modified in March 2001 to include user defined * operators for the floating point functions. * * This file is provided as is (no warranties). */ #if defined _float_included #endinput #endif #define _float_included /* Different methods of rounding */ enum floatround_method { floatround_round, floatround_floor, floatround_ceil } /**************************************************/ /* Convert an integer into a floating point value */ native float:float(value); /**************************************************/ /* Return the Current Time Delta as a float */ native float:GetTimeDelta(); /**************************************************/ /* Sin( degrees ) */ native float:Sin( degrees ); /**************************************************/ /* Cos( degrees ) */ native float:Cos( degrees ); /**************************************************/ /* Calculate the Square Root of a float */ native float:Sqrt( float:Number ); /**************************************************/ /* Convert a string into a floating point value */ native float:floatstr(const string[]); /**************************************************/ /* Multiple two floats together */ native float:floatmul(float:oper1, float:oper2); /**************************************************/ /* Divide the dividend float by the divisor float */ native float:floatdiv(float:dividend, float:divisor); /**************************************************/ /* Add two floats together */ native float:floatadd(float:dividend, float:divisor); /**************************************************/ /* Subtract oper2 float from oper1 float */ native float:floatsub(float:oper1, float:oper2); /**************************************************/ /* Return the fractional part of a float */ native float:floatfract(float:value); /**************************************************/ /* Round a float into a integer value */ native floatround(float:value, floatround_method:method=floatround_round); /**************************************************/ /* Compare two integers. If the two elements are equal, return 0. If the first argument is greater than the second argument, return 1, If the first argument is less than the second argument, return -1. */ native floatcmp(float:fOne, float:fTwo); /**************************************************/ #pragma rational float /* user defined operators */ native float:operator*(float:oper1, float:oper2) = floatmul; native float:operator/(float:oper1, float:oper2) = floatdiv; native float:operator+(float:oper1, float:oper2) = floatadd; native float:operator-(float:oper1, float:oper2) = floatsub; stock float:operator++(float:oper) return oper+1.0; stock float:operator--(float:oper) return oper-1.0; stock float:operator-(float:oper) return oper^float:0x80000000; /* IEEE values are sign/magnitude */ stock float:operator*(float:oper1, oper2) return floatmul(oper1, float(oper2)); /* "*" is commutative */ stock float:operator/(float:oper1, oper2) return floatdiv(oper1, float(oper2)); stock float:operator/(oper1, float:oper2) return floatdiv(float(oper1), oper2); stock float:operator+(float:oper1, oper2) return floatadd(oper1, float(oper2)); /* "+" is commutative */ stock float:operator-(float:oper1, oper2) return floatsub(oper1, float(oper2)); stock float:operator-(oper1, float:oper2) return floatsub(float(oper1), oper2); stock bool:operator==(float:oper1, float:oper2) return floatcmp(oper1, oper2) == 0; stock bool:operator==(float:oper1, oper2) return floatcmp(oper1, float(oper2)) == 0; /* "==" is commutative */ stock bool:operator!=(float:oper1, float:oper2) return floatcmp(oper1, oper2) != 0; stock bool:operator!=(float:oper1, oper2) return floatcmp(oper1, float(oper2)) != 0; /* "==" is commutative */ stock bool:operator>(float:oper1, float:oper2) return floatcmp(oper1, oper2) > 0; stock bool:operator>(float:oper1, oper2) return floatcmp(oper1, float(oper2)) > 0; stock bool:operator>(oper1, float:oper2) return floatcmp(float(oper1), oper2) > 0; stock bool:operator>=(float:oper1, float:oper2) return floatcmp(oper1, oper2) >= 0; stock bool:operator>=(float:oper1, oper2) return floatcmp(oper1, float(oper2)) >= 0; stock bool:operator>=(oper1, float:oper2) return floatcmp(float(oper1), oper2) >= 0; stock bool:operator<(float:oper1, float:oper2) return floatcmp(oper1, oper2) < 0; stock bool:operator<(float:oper1, oper2) return floatcmp(oper1, float(oper2)) < 0; stock bool:operator<(oper1, float:oper2) return floatcmp(float(oper1), oper2) < 0; stock bool:operator<=(float:oper1, float:oper2) return floatcmp(oper1, oper2) <= 0; stock bool:operator<=(float:oper1, oper2) return floatcmp(oper1, float(oper2)) <= 0; stock bool:operator<=(oper1, float:oper2) return floatcmp(float(oper1), oper2) <= 0; stock bool:operator!(float:oper) return floatcmp(oper1, 0.0) == 0; /* forbidden operations */ forward operator%(float:oper1, float:oper2); forward operator%(float:oper1, oper2); forward operator%(oper1, float:oper2);