Tizen 2.0 Release
[framework/uifw/embryo.git] / include / default.inc
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 */
27 enum Float_Round_Method
28 {
29    ROUND, FLOOR, CEIL, TOZERO
30 };
31 /* different angle addressing modes (default is radians) */
32 enum Float_Angle_Mode
33 {
34    RADIAN, DEGREES, GRADES
35 };
36
37 /* varags - get numebr of args to a function */
38 native numargs();
39 /* varags - get arg no "arg" */
40 native getarg(arg, index=0);
41 native getsarg(arg, buf[], buflen);
42 native Float:getfarg(arg, index=0);
43 /* varags - set arg no "arg" */
44 native setarg(arg, index=0, value);
45 native setfarg(arg, index=0, Float:value);
46
47 /* Convert a string into a floating point value */
48 native Float:atof(const string[]);
49 /* Return the fractional part of a float */
50 native Float:fract(Float:value);
51 /* Round a float into a integer value */
52 native       round(Float:value, Float_Round_Method:method=ROUND);
53 /* Return the square root of value, same as float_power(value, 0.5) */
54 native Float:sqrt(Float:value);
55 /* Return the value raised to the power of the exponent */
56 native Float:pow(Float:value, Float:exponent);
57 /* Return the logarithm */
58 native 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. */
61 native Float:sin(Float:value, Float_Angle_Mode:mode=RADIAN);
62 native Float:cos(Float:value, Float_Angle_Mode:mode=RADIAN);
63 native Float:tan(Float:value, Float_Angle_Mode:mode=RADIAN);
64 /* Return the absolute value */
65 native Float:abs(Float:value);
66 /* return integer from string */
67 native       atoi(str[]);
68 /* return 0 if string matches glob, non-zero otherwise */
69 native       fnmatch(glob[], str[]);
70 /* same as strcmp() */
71 native       strcmp(str1[], str2[]);
72 /* same as strncmp */
73 native       strncmp(str1[], str2[], n);
74 /* same as strcpy */
75 native       strcpy(dst[], src[]);
76 /* same as strncpy  except it nul terminates */
77 native       strncpy(dst[], src[], n);
78 /* same as strlen */
79 native       strlen(str[]);
80 /* same as strcat */
81 native       strcat(dst[], src[]);
82 /* same as strncat except it nul terminates */
83 native       strncat(dst[], src[], n);
84 /* prepends src string onto start of dst string */
85 native       strprep(dst[], src[]);
86 /* prepends at most n chars from src string onto dst string */
87 native       strnprep(dst[], src[], n);
88 /* cuts chars from char n to (not including) n2, and puts them in str */
89 native       strcut(dst[], str[], n, n2);
90 /* same as snprintf, except only supports %%, %c, %i, %d, %f, %x, %X, %s, \n and \t */
91 native       snprintf(dst[], dstn, fmt[], ...);
92 /* same as strstr */
93 native       strstr(str[], ndl[]);
94 /* same as strchr, except ch must be a 1 charater long string, and returns string index */
95 native       strchr(str[], ch[]);
96 /* same as strrchr, except ch must be a 1 charater long string and returns string index */
97 native       strrchr(str[], ch[]);
98 /* return random number 0 - 65535 */
99 native       rand();
100 /* return random number 0.0 - 1.0 */
101 native Float:randf();
102 /* return seconds since midnight as a float */
103 native Float:seconds();
104 /* return the current date, year, time etc. in the variables provided */
105 native       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 */
139 native Float:float(value);
140 /* Multiple two floats together */
141 native Float:float_mul(Float:oper1, Float:oper2);
142 /* Divide the dividend float by the divisor float */
143 native Float:float_div(Float:dividend, Float:divisor);
144 /* Add two floats together */
145 native Float:float_add(Float:oper1, Float:oper2);
146 /* Subtract oper2 float from oper1 float */
147 native 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. */
151 native       float_cmp(Float:oper1, Float:oper2);
152 /* user defined operators */
153 native Float:operator*(Float:oper1, Float:oper2) = float_mul;
154 native Float:operator/(Float:oper1, Float:oper2) = float_div;
155 native Float:operator+(Float:oper1, Float:oper2) = float_add;
156 native Float:operator-(Float:oper1, Float:oper2) = float_sub;
157 native Float:operator=(oper) = float;
158 stock Float:operator++(Float:oper)
159     return oper+1.0;
160 stock Float:operator--(Float:oper)
161     return oper-1.0;
162 stock Float:operator-(Float:oper)
163     return oper^Float:0x80000000; /* IEEE values are sign/magnitude */
164 stock Float:operator*(Float:oper1, oper2)
165     return float_mul(oper1, float(oper2)); /* "*" is commutative */
166 stock Float:operator/(Float:oper1, oper2)
167     return float_div(oper1, float(oper2));
168 stock Float:operator/(oper1, Float:oper2)
169     return float_div(float(oper1), oper2);
170 stock Float:operator+(Float:oper1, oper2)
171     return float_add(oper1, float(oper2)); /* "+" is commutative */
172 stock Float:operator-(Float:oper1, oper2)
173     return float_sub(oper1, float(oper2));
174 stock Float:operator-(oper1, Float:oper2)
175     return float_sub(float(oper1), oper2);
176 stock bool:operator==(Float:oper1, Float:oper2)
177     return float_cmp(oper1, oper2) == 0;
178 stock bool:operator==(Float:oper1, oper2)
179     return float_cmp(oper1, float(oper2)) == 0;  /* "==" is commutative */
180 stock bool:operator!=(Float:oper1, Float:oper2)
181     return float_cmp(oper1, oper2) != 0;
182 stock bool:operator!=(Float:oper1, oper2)
183     return float_cmp(oper1, float(oper2)) != 0;  /* "!=" is commutative */
184 stock bool:operator>(Float:oper1, Float:oper2)
185     return float_cmp(oper1, oper2) > 0;
186 stock bool:operator>(Float:oper1, oper2)
187     return float_cmp(oper1, float(oper2)) > 0;
188 stock bool:operator>(oper1, Float:oper2)
189     return float_cmp(float(oper1), oper2) > 0;
190 stock bool:operator>=(Float:oper1, Float:oper2)
191     return float_cmp(oper1, oper2) >= 0;
192 stock bool:operator>=(Float:oper1, oper2)
193     return float_cmp(oper1, float(oper2)) >= 0;
194 stock bool:operator>=(oper1, Float:oper2)
195     return float_cmp(float(oper1), oper2) >= 0;
196 stock bool:operator<(Float:oper1, Float:oper2)
197     return float_cmp(oper1, oper2) < 0;
198 stock bool:operator<(Float:oper1, oper2)
199     return float_cmp(oper1, float(oper2)) < 0;
200 stock bool:operator<(oper1, Float:oper2)
201     return float_cmp(float(oper1), oper2) < 0;
202 stock bool:operator<=(Float:oper1, Float:oper2)
203     return float_cmp(oper1, oper2) <= 0;
204 stock bool:operator<=(Float:oper1, oper2)
205     return float_cmp(oper1, float(oper2)) <= 0;
206 stock bool:operator<=(oper1, Float:oper2)
207     return float_cmp(float(oper1), oper2) <= 0;
208 stock bool:operator!(Float:oper)
209     return (_:oper & 0x7fffffff) == 0;
210 /* forbidden operations */
211 forward operator%(Float:oper1, Float:oper2);
212 forward operator%(Float:oper1, oper2);
213 forward operator%(oper1, Float:oper2);
214
215 /**************************************************************************/
216 /* ADDED in embryo 1.2                                                    */
217 /**************************************************************************/
218 /* use this to determine embryo age */
219 #define EMBRYO_12 12
220 /* Return the inverse sine, cosine or tangent. The output may be radians, */
221 /* degrees or grades. */
222 native Float:asin(Float:value, Float_Angle_Mode:mode=RADIAN);
223 native Float:acos(Float:value, Float_Angle_Mode:mode=RADIAN);
224 native Float:atan(Float:value, Float_Angle_Mode:mode=RADIAN);
225 native Float:atan2(Float:valuey, Float:valuex, Float_Angle_Mode:mode=RADIAN);
226 /* same as libc functions */
227 native Float:log1p(Float:value);
228 native Float:cbrt(Float:value);
229 native Float:exp(Float:value);
230 native Float:exp2(Float:value);
231 native Float:hypot(Float:valuex, Float:valuey);