dfdffdfdfdfd commited on
Commit
8b7722f
·
verified ·
1 Parent(s): d3ce870

Create float.inc

Browse files
Files changed (1) hide show
  1. float.inc +183 -0
float.inc ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
16
+ /* Different methods of rounding */
17
+ enum floatround_method {
18
+ floatround_round,
19
+ floatround_floor,
20
+ floatround_ceil,
21
+ floatround_tozero,
22
+ floatround_unbiased
23
+ }
24
+ enum anglemode {
25
+ radian,
26
+ degrees,
27
+ grades
28
+ }
29
+
30
+ /**************************************************/
31
+ /* Convert an integer into a floating point value */
32
+ native Float:float(value);
33
+
34
+ /**************************************************/
35
+ /* Convert a string into a floating point value */
36
+ native Float:floatstr(const string[]);
37
+
38
+ /**************************************************/
39
+ /* Multiple two floats together */
40
+ native Float:floatmul(Float:oper1, Float:oper2);
41
+
42
+ /**************************************************/
43
+ /* Divide the dividend float by the divisor float */
44
+ native Float:floatdiv(Float:dividend, Float:divisor);
45
+
46
+ /**************************************************/
47
+ /* Add two floats together */
48
+ native Float:floatadd(Float:oper1, Float:oper2);
49
+
50
+ /**************************************************/
51
+ /* Subtract oper2 float from oper1 float */
52
+ native Float:floatsub(Float:oper1, Float:oper2);
53
+
54
+ /**************************************************/
55
+ /* Return the fractional part of a float */
56
+ native Float:floatfract(Float:value);
57
+
58
+ /**************************************************/
59
+ /* Round a float into a integer value */
60
+ native floatround(Float:value, floatround_method:method=floatround_round);
61
+
62
+ /**************************************************/
63
+ /* Compare two integers. If the two elements are equal, return 0.
64
+ If the first argument is greater than the second argument, return 1,
65
+ If the first argument is less than the second argument, return -1. */
66
+ native floatcmp(Float:oper1, Float:oper2);
67
+
68
+ /**************************************************/
69
+ /* Return the square root of the input value, same as floatpower(value, 0.5) */
70
+ native Float:floatsqroot(Float:value);
71
+
72
+ /**************************************************/
73
+ /* Return the value raised to the power of the exponent */
74
+ native Float:floatpower(Float:value, Float:exponent);
75
+
76
+ /**************************************************/
77
+ /* Return the logarithm */
78
+ native Float:floatlog(Float:value, Float:base=10.0);
79
+
80
+ /**************************************************/
81
+ /* Return the sine, cosine or tangent. The input angle may be in radian,
82
+ degrees or grades. */
83
+ native Float:floatsin(Float:value, anglemode:mode=radian);
84
+ native Float:floatcos(Float:value, anglemode:mode=radian);
85
+ native Float:floattan(Float:value, anglemode:mode=radian);
86
+
87
+ /**************************************************/
88
+ /* Return the absolute value */
89
+ native Float:floatabs(Float:value);
90
+
91
+
92
+ /**************************************************/
93
+ #pragma rational Float
94
+
95
+ /* user defined operators */
96
+ native Float:operator*(Float:oper1, Float:oper2) = floatmul;
97
+ native Float:operator/(Float:oper1, Float:oper2) = floatdiv;
98
+ native Float:operator+(Float:oper1, Float:oper2) = floatadd;
99
+ native Float:operator-(Float:oper1, Float:oper2) = floatsub;
100
+ native Float:operator=(oper) = float;
101
+
102
+ stock Float:operator++(Float:oper)
103
+ return oper+1.0;
104
+
105
+ stock Float:operator--(Float:oper)
106
+ return oper-1.0;
107
+
108
+ stock Float:operator-(Float:oper)
109
+ return oper^Float:cellmin; /* IEEE values are sign/magnitude */
110
+
111
+ stock Float:operator*(Float:oper1, oper2)
112
+ return floatmul(oper1, float(oper2)); /* "*" is commutative */
113
+
114
+ stock Float:operator/(Float:oper1, oper2)
115
+ return floatdiv(oper1, float(oper2));
116
+
117
+ stock Float:operator/(oper1, Float:oper2)
118
+ return floatdiv(float(oper1), oper2);
119
+
120
+ stock Float:operator+(Float:oper1, oper2)
121
+ return floatadd(oper1, float(oper2)); /* "+" is commutative */
122
+
123
+ stock Float:operator-(Float:oper1, oper2)
124
+ return floatsub(oper1, float(oper2));
125
+
126
+ stock Float:operator-(oper1, Float:oper2)
127
+ return floatsub(float(oper1), oper2);
128
+
129
+ stock bool:operator==(Float:oper1, Float:oper2)
130
+ return floatcmp(oper1, oper2) == 0;
131
+
132
+ stock bool:operator==(Float:oper1, oper2)
133
+ return floatcmp(oper1, float(oper2)) == 0; /* "==" is commutative */
134
+
135
+ stock bool:operator!=(Float:oper1, Float:oper2)
136
+ return floatcmp(oper1, oper2) != 0;
137
+
138
+ stock bool:operator!=(Float:oper1, oper2)
139
+ return floatcmp(oper1, float(oper2)) != 0; /* "!=" is commutative */
140
+
141
+ stock bool:operator>(Float:oper1, Float:oper2)
142
+ return floatcmp(oper1, oper2) > 0;
143
+
144
+ stock bool:operator>(Float:oper1, oper2)
145
+ return floatcmp(oper1, float(oper2)) > 0;
146
+
147
+ stock bool:operator>(oper1, Float:oper2)
148
+ return floatcmp(float(oper1), oper2) > 0;
149
+
150
+ stock bool:operator>=(Float:oper1, Float:oper2)
151
+ return floatcmp(oper1, oper2) >= 0;
152
+
153
+ stock bool:operator>=(Float:oper1, oper2)
154
+ return floatcmp(oper1, float(oper2)) >= 0;
155
+
156
+ stock bool:operator>=(oper1, Float:oper2)
157
+ return floatcmp(float(oper1), oper2) >= 0;
158
+
159
+ stock bool:operator<(Float:oper1, Float:oper2)
160
+ return floatcmp(oper1, oper2) < 0;
161
+
162
+ stock bool:operator<(Float:oper1, oper2)
163
+ return floatcmp(oper1, float(oper2)) < 0;
164
+
165
+ stock bool:operator<(oper1, Float:oper2)
166
+ return floatcmp(float(oper1), oper2) < 0;
167
+
168
+ stock bool:operator<=(Float:oper1, Float:oper2)
169
+ return floatcmp(oper1, oper2) <= 0;
170
+
171
+ stock bool:operator<=(Float:oper1, oper2)
172
+ return floatcmp(oper1, float(oper2)) <= 0;
173
+
174
+ stock bool:operator<=(oper1, Float:oper2)
175
+ return floatcmp(float(oper1), oper2) <= 0;
176
+
177
+ stock bool:operator!(Float:oper)
178
+ return (_:oper & cellmax) == 0;
179
+
180
+ /* forbidden operations */
181
+ forward operator%(Float:oper1, Float:oper2);
182
+ forward operator%(Float:oper1, oper2);
183
+ forward operator%(oper1, Float:oper2);