I have often been bit by this feature of squeak. '1234.123E-5' asNumber produces 1234.123 because the exponent part is ignored. Some numeric software produces output in this format, and reading datafiles from such programs may lead to very hard to trace anomalies (especially when scientific notation is only used for some of the numbers). A simple one-liner change in Number>>readRemainderOf:from:base:withSign: seems sufficient to handle capital E, see attached fileout.
I changed "peekChar = $e | (peekChar = $d) | (peekChar = $q)"
to "((((peekChar == $e) or: [peekChar == $E]) or: [peekChar == $d]) or: [peekChar == $q])"
(I compensated for the extra check by replacing the bars by blocks).
I can't imagine there are any unwelcome side-effects associated with this change?
==================================== Hans Baveco
<<Number class-readRemainderOffrombasewithSign.st>>
Am 01.12.2004 um 10:15 schrieb Baveco, Hans:
I have often been bit by this feature of squeak. '1234.123E-5' asNumber produces 1234.123 because the exponent part is ignored. Some numeric software produces output in this format, and reading datafiles from such programs may lead to very hard to trace anomalies (especially when scientific notation is only used for some of the numbers). A simple one-liner change in Number>>readRemainderOf:from:base:withSign: seems sufficient to handle capital E, see attached fileout.
I changed "peekChar = $e | (peekChar = $d) | (peekChar = $q)"
to "((((peekChar == $e) or: [peekChar == $E]) or: [peekChar == $d]) or: [peekChar == $q])"
(I compensated for the extra check by replacing the bars by blocks).
I can't imagine there are any unwelcome side-effects associated with this change?
It changes the language, as this method is also used for reading literal numbers. I've been down that road before and was educated by Dan Ingalls that things are as they are for a reason.
The reason in this case is that uppercase letters are reserved for digits (think hexadecimal). You can enter literal floats up to base 36 in Smalltalk: 16rABC.DEF
So, just convert your numbers to lowercase before reading them in.
- Bert -
squeak-dev@lists.squeakfoundation.org