aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/embryo/include/default.inc
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/embryo/include/default.inc')
-rw-r--r--libraries/embryo/include/default.inc213
1 files changed, 213 insertions, 0 deletions
diff --git a/libraries/embryo/include/default.inc b/libraries/embryo/include/default.inc
new file mode 100644
index 0000000..0733503
--- /dev/null
+++ b/libraries/embryo/include/default.inc
@@ -0,0 +1,213 @@
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 * (c) Copyright 2004, Carsten Haitzler
8 * Modified March 2004 by Carsten Haitzler <raster@rasterman.com> to conform
9 * to E coding style
10 * Became default include for embryo...
11 * Added string functions
12 * Added rand functions
13 * Added time functions
14 *
15 * This file is provided as is (no warranties).
16 */
17#if defined DEFAULT_INC
18#endinput
19#endif
20#define DEFAULT_INC
21
22#pragma rational Float
23
24#define PI 3.1415926535897932384626433832795
25
26/* Different methods of rounding */
27enum Float_Round_Method
28{
29 ROUND, FLOOR, CEIL, TOZERO
30};
31/* different angle addressing modes (default is radians) */
32enum Float_Angle_Mode
33{
34 RADIAN, DEGREES, GRADES
35};
36
37/* varags - get numebr of args to a function */
38native numargs();
39/* varags - get arg no "arg" */
40native getarg(arg, index=0);
41native getsarg(arg, buf[], buflen);
42native Float:getfarg(arg, index=0);
43/* varags - set arg no "arg" */
44native setarg(arg, index=0, value);
45native setfarg(arg, index=0, Float:value);
46
47/* Convert a string into a floating point value */
48native Float:atof(const string[]);
49/* Return the fractional part of a float */
50native Float:fract(Float:value);
51/* Round a float into a integer value */
52native round(Float:value, Float_Round_Method:method=ROUND);
53/* Return the square root of value, same as float_power(value, 0.5) */
54native Float:sqrt(Float:value);
55/* Return the value raised to the power of the exponent */
56native Float:pow(Float:value, Float:exponent);
57/* Return the logarithm */
58native Float:log(Float:value, Float:base=10.0);
59/* Return the sine, cosine or tangent. The input angle may be in radian*/
60/* degrees or grades. */
61native Float:sin(Float:value, Float_Angle_Mode:mode=RADIAN);
62native Float:cos(Float:value, Float_Angle_Mode:mode=RADIAN);
63native Float:tan(Float:value, Float_Angle_Mode:mode=RADIAN);
64/* Return the absolute value */
65native Float:abs(Float:value);
66/* return integer from string */
67native atoi(str[]);
68/* return 0 if string matches glob, non-zero otherwise */
69native fnmatch(glob[], str[]);
70/* same as strcmp() */
71native strcmp(str1[], str2[]);
72/* same as strncmp */
73native strncmp(str1[], str2[], n);
74/* same as strcpy */
75native strcpy(dst[], src[]);
76/* same as strncpy except it nul terminates */
77native strncpy(dst[], src[], n);
78/* same as strlen */
79native strlen(str[]);
80/* same as strcat */
81native strcat(dst[], src[]);
82/* same as strncat except it nul terminates */
83native strncat(dst[], src[], n);
84/* prepends src string onto start of dst string */
85native strprep(dst[], src[]);
86/* prepends at most n chars from src string onto dst string */
87native strnprep(dst[], src[], n);
88/* cuts chars from char n to (not including) n2, and puts them in str */
89native strcut(dst[], str[], n, n2);
90/* same as snprintf, except only supports %%, %c, %i, %d, %f, %x, %X, %s, \n and \t */
91native snprintf(dst[], dstn, fmt[], ...);
92/* same as strstr */
93native strstr(str[], ndl[]);
94/* same as strchr, except ch must be a 1 charater long string, and returns string index */
95native strchr(str[], ch[]);
96/* same as strrchr, except ch must be a 1 charater long string and returns string index */
97native strrchr(str[], ch[]);
98/* return random number 0 - 65535 */
99native rand();
100/* return random number 0.0 - 1.0 */
101native Float:randf();
102/* return seconds since midnight as a float */
103native Float:seconds();
104/* return the current date, year, time etc. in the variables provided */
105native date(&year, &month, &day, &yearday, &weekday, &hr, &min, &Float:sec);
106
107/*****************************************************************************/
108/*****************************************************************************/
109/*****************************************************************************/
110/*****************************************************************************/
111/*****************************************************************************/
112/*****************************************************************************/
113/*****************************************************************************/
114/*****************************************************************************/
115/*****************************************************************************/
116/*****************************************************************************/
117/*****************************************************************************/
118/*****************************************************************************/
119/*****************************************************************************/
120/*****************************************************************************/
121/*****************************************************************************/
122/*****************************************************************************/
123/*****************************************************************************/
124/*****************************************************************************/
125/*****************************************************************************/
126/*****************************************************************************/
127/*****************************************************************************/
128/*****************************************************************************/
129/*****************************************************************************/
130/*****************************************************************************/
131/*****************************************************************************/
132/*****************************************************************************/
133
134/**************************************************/
135/* Hidden calls - all are overloaded on operators */
136/**************************************************/
137
138/* Convert an integer into a floating point value */
139native Float:float(value);
140/* Multiple two floats together */
141native Float:float_mul(Float:oper1, Float:oper2);
142/* Divide the dividend float by the divisor float */
143native Float:float_div(Float:dividend, Float:divisor);
144/* Add two floats together */
145native Float:float_add(Float:oper1, Float:oper2);
146/* Subtract oper2 float from oper1 float */
147native Float:float_sub(Float:oper1, Float:oper2);
148/* Compare two integers. If the two elements are equal, return 0. */
149/* If the first argument is greater than the second argument, return 1, */
150/* If the first argument is less than the second argument, return -1. */
151native float_cmp(Float:oper1, Float:oper2);
152/* user defined operators */
153native Float:operator*(Float:oper1, Float:oper2) = float_mul;
154native Float:operator/(Float:oper1, Float:oper2) = float_div;
155native Float:operator+(Float:oper1, Float:oper2) = float_add;
156native Float:operator-(Float:oper1, Float:oper2) = float_sub;
157native Float:operator=(oper) = float;
158stock Float:operator++(Float:oper)
159 return oper+1.0;
160stock Float:operator--(Float:oper)
161 return oper-1.0;
162stock Float:operator-(Float:oper)
163 return oper^Float:0x80000000; /* IEEE values are sign/magnitude */
164stock Float:operator*(Float:oper1, oper2)
165 return float_mul(oper1, float(oper2)); /* "*" is commutative */
166stock Float:operator/(Float:oper1, oper2)
167 return float_div(oper1, float(oper2));
168stock Float:operator/(oper1, Float:oper2)
169 return float_div(float(oper1), oper2);
170stock Float:operator+(Float:oper1, oper2)
171 return float_add(oper1, float(oper2)); /* "+" is commutative */
172stock Float:operator-(Float:oper1, oper2)
173 return float_sub(oper1, float(oper2));
174stock Float:operator-(oper1, Float:oper2)
175 return float_sub(float(oper1), oper2);
176stock bool:operator==(Float:oper1, Float:oper2)
177 return float_cmp(oper1, oper2) == 0;
178stock bool:operator==(Float:oper1, oper2)
179 return float_cmp(oper1, float(oper2)) == 0; /* "==" is commutative */
180stock bool:operator!=(Float:oper1, Float:oper2)
181 return float_cmp(oper1, oper2) != 0;
182stock bool:operator!=(Float:oper1, oper2)
183 return float_cmp(oper1, float(oper2)) != 0; /* "!=" is commutative */
184stock bool:operator>(Float:oper1, Float:oper2)
185 return float_cmp(oper1, oper2) > 0;
186stock bool:operator>(Float:oper1, oper2)
187 return float_cmp(oper1, float(oper2)) > 0;
188stock bool:operator>(oper1, Float:oper2)
189 return float_cmp(float(oper1), oper2) > 0;
190stock bool:operator>=(Float:oper1, Float:oper2)
191 return float_cmp(oper1, oper2) >= 0;
192stock bool:operator>=(Float:oper1, oper2)
193 return float_cmp(oper1, float(oper2)) >= 0;
194stock bool:operator>=(oper1, Float:oper2)
195 return float_cmp(float(oper1), oper2) >= 0;
196stock bool:operator<(Float:oper1, Float:oper2)
197 return float_cmp(oper1, oper2) < 0;
198stock bool:operator<(Float:oper1, oper2)
199 return float_cmp(oper1, float(oper2)) < 0;
200stock bool:operator<(oper1, Float:oper2)
201 return float_cmp(float(oper1), oper2) < 0;
202stock bool:operator<=(Float:oper1, Float:oper2)
203 return float_cmp(oper1, oper2) <= 0;
204stock bool:operator<=(Float:oper1, oper2)
205 return float_cmp(oper1, float(oper2)) <= 0;
206stock bool:operator<=(oper1, Float:oper2)
207 return float_cmp(float(oper1), oper2) <= 0;
208stock bool:operator!(Float:oper)
209 return (_:oper & 0x7fffffff) == 0;
210/* forbidden operations */
211forward operator%(Float:oper1, Float:oper2);
212forward operator%(Float:oper1, oper2);
213forward operator%(oper1, Float:oper2);