Changeset 175 for trunk/thune/eval.c
- Timestamp:
- 06/08/06 22:00:46 (3 years ago)
- Files:
-
- 1 modified
-
trunk/thune/eval.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/eval.c
r172 r175 1193 1193 1194 1194 1195 // (number number -- number) 1195 #define MJ_INT_INT 0 1196 #define MJ_INT_DEC 1 1197 #define MJ_DEC_INT 2 1198 #define MJ_DEC_DEC 3 1199 #define MJ_NAN 4 1200 1201 static int _mathJumpIndex( const UCell* a, const UCell* b ) 1202 { 1203 if( ur_is(a, UT_INT) ) 1204 { 1205 if( ur_is(b, UT_INT) ) 1206 return MJ_INT_INT; 1207 if( ur_is(b, UT_DECIMAL) ) 1208 return MJ_INT_DEC; 1209 } 1210 else if( ur_is(a, UT_DECIMAL) ) 1211 { 1212 if( ur_is(b, UT_INT) ) 1213 return MJ_DEC_INT; 1214 if( ur_is(b, UT_DECIMAL) ) 1215 return MJ_DEC_DEC; 1216 } 1217 return MJ_NAN; 1218 } 1219 1220 1221 #define MATH_OPERATION(OP) \ 1222 switch( _mathJumpIndex(res, tos) ) { \ 1223 case MJ_INT_INT: \ 1224 ur_int(res) = ur_int(res) OP ur_int(tos); \ 1225 break; \ 1226 case MJ_INT_DEC: \ 1227 ur_setType(res, UT_DECIMAL); \ 1228 ur_decimal(res) = ((double) ur_int(res)) OP ur_decimal(tos); \ 1229 break; \ 1230 case MJ_DEC_INT: \ 1231 ur_decimal(res) = ur_decimal(res) OP ((double) ur_int(tos)); \ 1232 break; \ 1233 case MJ_DEC_DEC: \ 1234 ur_decimal(res) = ur_decimal(res) OP ur_decimal(tos); \ 1235 break; \ 1236 case MJ_NAN: \ 1237 ur_throwErr( ur_thread, UR_EX_DATATYPE, \ 1238 "Math operator requires int!/decimal!" ); \ 1239 break; \ 1240 } 1241 1242 1243 // (number number -- sum) 1196 1244 UR_CALL( uc_add ) 1197 1245 { … … 1203 1251 else 1204 1252 { 1205 ur_int(UR_TOS) += ur_int(tos); 1206 } 1207 } 1208 1209 1210 // (number number -- diff) 1253 UCell* res = UR_TOS; 1254 MATH_OPERATION( + ) 1255 } 1256 } 1257 1258 1259 // (number number -- difference) 1211 1260 UR_CALL( uc_sub ) 1212 1261 { … … 1218 1267 else 1219 1268 { 1220 ur_int(UR_TOS) -= ur_int(tos); 1221 } 1222 } 1223 1224 1225 // (number number -- number) 1269 UCell* res = UR_TOS; 1270 MATH_OPERATION( - ) 1271 } 1272 } 1273 1274 1275 // (number number -- product) 1226 1276 UR_CALL( uc_mult ) 1227 1277 { 1278 UCell* res; 1279 1228 1280 UR_S_DROP; 1229 ur_int(UR_TOS) *= ur_int(tos); 1281 res = UR_TOS; 1282 1283 MATH_OPERATION( * ) 1284 } 1285 1286 1287 // (number number -- quotient) 1288 UR_CALL( uc_div ) 1289 { 1290 UCell* res; 1291 1292 UR_S_DROP; 1293 res = UR_TOS; 1294 1295 MATH_OPERATION( / ) 1230 1296 } 1231 1297 … … 1954 2020 { uc_sub, "sub" }, 1955 2021 { uc_mult, "mult" }, 2022 { uc_div, "div" }, 1956 2023 { uc_equal, "eq?" }, 1957 2024 { uc_sameQ, "same?" },
