summaryrefslogtreecommitdiff
path: root/data/embryo/default.inc
blob: 7855ac8ec7e1bd840504d0c4f31081be76dbdb57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* 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.
 * (c) Copyright 2004, Carsten Haitzler
 * Modified March 2004 by Carsten Haitzler <raster@rasterman.com> to conform
 * to E coding style
 * Became default include for embryo...
 * Added string functions
 * Added rand functions
 * Added time functions
 *
 * This file is provided as is (no warranties).
 */
#if defined DEFAULT_INC
#endinput
#endif
#define DEFAULT_INC

#pragma rational Float

#define PI  3.1415926535897932384626433832795

/* Different methods of rounding */
enum Float_Round_Method
{
   ROUND, FLOOR, CEIL, TOZERO
};
/* different angle addressing modes (default is radians) */
enum Float_Angle_Mode
{
   RADIAN, DEGREES, GRADES
};

/* varags - get numebr of args to a function */
native numargs();
/* varags - get arg no "arg" */
native getarg(arg, index=0);
native getsarg(arg, buf[], buflen);
native Float:getfarg(arg, index=0);
/* varags - set arg no "arg" */
native setarg(arg, index=0, value);
native setfarg(arg, index=0, Float:value);

/* Convert a string into a floating point value */
native Float:atof(const string[]);
/* Return the fractional part of a float */
native Float:fract(Float:value);
/* Round a float into a integer value */
native       round(Float:value, Float_Round_Method:method=ROUND);
/* Return the square root of value, same as float_power(value, 0.5) */
native Float:sqrt(Float:value);
/* Return the value raised to the power of the exponent */
native Float:pow(Float:value, Float:exponent);
/* Return the logarithm */
native Float:log(Float:value, Float:base=10.0);
/* Return the sine, cosine or tangent. The input angle may be in radian*/
/* degrees or grades. */
native Float:sin(Float:value, Float_Angle_Mode:mode=RADIAN);
native Float:cos(Float:value, Float_Angle_Mode:mode=RADIAN);
native Float:tan(Float:value, Float_Angle_Mode:mode=RADIAN);
/* Return the absolute value */
native Float:abs(Float:value);
/* return integer from string */
native       atoi(str[]);
/* return 0 if string matches glob, non-zero otherwise */
native       fnmatch(glob[], str[]);
/* same as strcmp() */
native       strcmp(str1[], str2[]);
/* same as strncmp */
native       strncmp(str1[], str2[], n);
/* same as strcpy */
native       strcpy(dst[], src[]);
/* same as strncpy  except it nul terminates */
native       strncpy(dst[], src[], n);
/* same as strlen */
native       strlen(str[]);
/* same as strcat */
native       strcat(dst[], src[]);
/* same as strncat except it nul terminates */
native       strncat(dst[], src[], n);
/* prepends src string onto start of dst string */
native       strprep(dst[], src[]);
/* prepends at most n chars from src string onto dst string */
native       strnprep(dst[], src[], n);
/* cuts chars from char n to (not including) n2, and puts them in str */
native       strcut(dst[], str[], n, n2);
/* same as snprintf, except only supports %%, %c, %i, %d, %f, %x, %X, %s, \n and \t */
native       snprintf(dst[], dstn, fmt[], ...);
/* same as strstr */
native       strstr(str[], ndl[]);
/* same as strchr, except ch must be a 1 charater long string, and returns string index */
native       strchr(str[], ch[]);
/* same as strrchr, except ch must be a 1 charater long string and returns string index */
native       strrchr(str[], ch[]);
/* same as printf, except only supports %%, %c, %i, %d, %f, %x, %X, %s, \n and \t */
native       printf(fmt[], ...);
/* return random number 0 - 65535 */
native       rand();
/* return random number 0.0 - 1.0 */
native Float:randf();
/* return seconds since midnight as a float */
native Float:seconds();
/* return the current date, year, time etc. in the variables provided */
native       date(&year, &month, &day, &yearday, &weekday, &hr, &min, &Float:sec);

/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/

/**************************************************/
/* Hidden calls - all are overloaded on operators */
/**************************************************/

/* Convert an integer into a floating point value */
native Float:float(value);
/* Multiple two floats together */
native Float:float_mul(Float:oper1, Float:oper2);
/* Divide the dividend float by the divisor float */
native Float:float_div(Float:dividend, Float:divisor);
/* Add two floats together */
native Float:float_add(Float:oper1, Float:oper2);
/* Subtract oper2 float from oper1 float */
native Float:float_sub(Float:oper1, Float:oper2);
/* 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       float_cmp(Float:oper1, Float:oper2);
/* user defined operators */
native Float:operator*(Float:oper1, Float:oper2) = float_mul;
native Float:operator/(Float:oper1, Float:oper2) = float_div;
native Float:operator+(Float:oper1, Float:oper2) = float_add;
native Float:operator-(Float:oper1, Float:oper2) = float_sub;
native Float:operator=(oper) = float;
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 float_mul(oper1, float(oper2)); /* "*" is commutative */
stock Float:operator/(Float:oper1, oper2)
    return float_div(oper1, float(oper2));
stock Float:operator/(oper1, Float:oper2)
    return float_div(float(oper1), oper2);
stock Float:operator+(Float:oper1, oper2)
    return float_add(oper1, float(oper2)); /* "+" is commutative */
stock Float:operator-(Float:oper1, oper2)
    return float_sub(oper1, float(oper2));
stock Float:operator-(oper1, Float:oper2)
    return float_sub(float(oper1), oper2);
stock bool:operator==(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) == 0;
stock bool:operator==(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) == 0;  /* "==" is commutative */
stock bool:operator!=(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) != 0;
stock bool:operator!=(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) != 0;  /* "!=" is commutative */
stock bool:operator>(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) > 0;
stock bool:operator>(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) > 0;
stock bool:operator>(oper1, Float:oper2)
    return float_cmp(float(oper1), oper2) > 0;
stock bool:operator>=(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) >= 0;
stock bool:operator>=(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) >= 0;
stock bool:operator>=(oper1, Float:oper2)
    return float_cmp(float(oper1), oper2) >= 0;
stock bool:operator<(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) < 0;
stock bool:operator<(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) < 0;
stock bool:operator<(oper1, Float:oper2)
    return float_cmp(float(oper1), oper2) < 0;
stock bool:operator<=(Float:oper1, Float:oper2)
    return float_cmp(oper1, oper2) <= 0;
stock bool:operator<=(Float:oper1, oper2)
    return float_cmp(oper1, float(oper2)) <= 0;
stock bool:operator<=(oper1, Float:oper2)
    return float_cmp(float(oper1), oper2) <= 0;
stock bool:operator!(Float:oper)
    return (_:oper & 0x7fffffff) == 0;
/* forbidden operations */
forward operator%(Float:oper1, Float:oper2);
forward operator%(Float:oper1, oper2);
forward operator%(oper1, Float:oper2);

/**************************************************************************/
/* ADDED in embryo 1.2                                                    */
/**************************************************************************/
/* use this to determine embryo age */
#define EMBRYO_12 12
/* Return the inverse sine, cosine or tangent. The output may be radians, */
/* degrees or grades. */
native Float:asin(Float:value, Float_Angle_Mode:mode=RADIAN);
native Float:acos(Float:value, Float_Angle_Mode:mode=RADIAN);
native Float:atan(Float:value, Float_Angle_Mode:mode=RADIAN);
native Float:atan2(Float:valuey, Float:valuex, Float_Angle_Mode:mode=RADIAN);
/* same as libc functions */
native Float:log1p(Float:value);
native Float:cbrt(Float:value);
native Float:exp(Float:value);
native Float:exp2(Float:value);
native Float:hypot(Float:valuex, Float:valuey);

/**************************************************************************/
/* ADDED in embryo 1.18                                                    */
/**************************************************************************/
#define EMBRYO_118 118
/* return the current date, year, time etc. in the variables provided modified by timezone tz */
native       tzdate(tz[], &year, &month, &day, &yearday, &weekday, &hr, &min, &Float:sec);