equal
deleted
inserted
replaced
234 returns garbage if the argument string is not a valid float number. |
234 returns garbage if the argument string is not a valid float number. |
235 It has been added to allow higher speed string decomposition into numbers, |
235 It has been added to allow higher speed string decomposition into numbers, |
236 especially for mass-data." |
236 especially for mass-data." |
237 |
237 |
238 %{ /* NOCONTEXT */ |
238 %{ /* NOCONTEXT */ |
239 if (__isString(aString) && __isSmallInteger(startIndex)) { |
239 if (__isStringLike(aString) && __isSmallInteger(startIndex)) { |
240 char *cp = (char *)(__stringVal(aString)); |
240 char *cp = (char *)(__stringVal(aString)); |
241 int idx = __intVal(startIndex) - 1; |
241 int idx = __intVal(startIndex) - 1; |
242 double atof(); |
242 double atof(); |
243 double val; |
243 double val; |
244 |
244 |
245 if ((unsigned)idx < __stringSize(aString)) { |
245 if ((unsigned)idx < __stringSize(aString)) { |
246 val = atof(cp + idx); |
246 val = atof(cp + idx); |
247 RETURN (__MKSFLOAT(val)); |
247 RETURN (__MKSFLOAT(val)); |
248 } |
248 } |
249 } |
249 } |
250 %}. |
250 %}. |
251 self primitiveFailed. |
251 self primitiveFailed. |
252 |
252 |
253 " |
253 " |
263 ShortFloat fastFromString:'12345' at:6 |
263 ShortFloat fastFromString:'12345' at:6 |
264 ShortFloat fastFromString:'12345' at:0 |
264 ShortFloat fastFromString:'12345' at:0 |
265 ShortFloat fastFromString:'hello123.45E4' at:1 |
265 ShortFloat fastFromString:'hello123.45E4' at:1 |
266 |
266 |
267 Time millisecondsToRun:[ |
267 Time millisecondsToRun:[ |
268 100000 timesRepeat:[ |
268 100000 timesRepeat:[ |
269 ShortFloat readFrom:'123.45' |
269 ShortFloat readFrom:'123.45' |
270 ] |
270 ] |
271 ] |
271 ] |
272 " |
272 " |
273 |
273 |
274 " |
274 " |
275 Time millisecondsToRun:[ |
275 Time millisecondsToRun:[ |
276 100000 timesRepeat:[ |
276 100000 timesRepeat:[ |
277 ShortFloat fastFromString:'123.45' at:1 |
277 ShortFloat fastFromString:'123.45' at:1 |
278 ] |
278 ] |
279 ] |
279 ] |
280 " |
280 " |
281 |
|
282 |
|
283 |
|
284 ! |
281 ! |
285 |
282 |
286 readFrom:aStringOrStream |
283 readFrom:aStringOrStream |
287 "read a shortFloat from a string" |
284 "read a shortFloat from a string" |
288 |
285 |
1020 %{ /* STACK: 400 */ |
1017 %{ /* STACK: 400 */ |
1021 char buffer[256]; |
1018 char buffer[256]; |
1022 OBJ s; |
1019 OBJ s; |
1023 int len; |
1020 int len; |
1024 |
1021 |
1025 if (__isString(formatString)) { |
1022 if (__isStringLike(formatString)) { |
1026 /* |
1023 /* |
1027 * actually only needed on sparc: since thisContext is |
1024 * actually only needed on sparc: since thisContext is |
1028 * in a global register, which gets destroyed by printf, |
1025 * in a global register, which gets destroyed by printf, |
1029 * manually save it here - very stupid ... |
1026 * manually save it here - very stupid ... |
1030 */ |
1027 */ |
1031 __BEGIN_PROTECT_REGISTERS__ |
1028 __BEGIN_PROTECT_REGISTERS__ |
1032 |
1029 |
1033 len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __shortFloatVal(self)); |
1030 len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __shortFloatVal(self)); |
1034 |
1031 |
1035 __END_PROTECT_REGISTERS__ |
1032 __END_PROTECT_REGISTERS__ |
1036 |
1033 |
1037 if (len < 0) goto fail; |
1034 if (len < 0) goto fail; |
1038 |
1035 |
1039 s = __MKSTRING_L(buffer, len); |
1036 s = __MKSTRING_L(buffer, len); |
1040 if (s != nil) { |
1037 if (s != nil) { |
1041 RETURN (s); |
1038 RETURN (s); |
1042 } |
1039 } |
1043 } |
1040 } |
1044 fail: ; |
1041 fail: ; |
1045 %}. |
1042 %}. |
1046 self primitiveFailed |
1043 self primitiveFailed |
1047 |
1044 |
1637 ! ! |
1634 ! ! |
1638 |
1635 |
1639 !ShortFloat class methodsFor:'documentation'! |
1636 !ShortFloat class methodsFor:'documentation'! |
1640 |
1637 |
1641 version |
1638 version |
1642 ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.100 2009-09-16 17:08:24 cg Exp $' |
1639 ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.101 2009-11-05 16:26:31 stefan Exp $' |
|
1640 ! |
|
1641 |
|
1642 version_CVS |
|
1643 ^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.101 2009-11-05 16:26:31 stefan Exp $' |
1643 ! ! |
1644 ! ! |