Number comparison gotcha
Bill Frantz <[email protected]>
| Newsgroups | gmane.comp.lang.e.general |
|---|---|
| Message-ID | <r314ps-1066i-8B10B1B54E4F4829B74EA21247893230@Bill-Frantzs-MacBook-Pro.local> |
I'm using E to do some statistics on the output of some data
temperature/light level loggers. In processing the output into
usable form, I substituted -5000 for any missing or invalid values.
In a statistical program, I convert the string values of the
measurements to float64 with:
<import:java.lang.makeDouble>.parseDouble(numberAsString)
(Ugly but functional) making "value" in the example below a
float64 number.
I included the test in a statistical program it skip missing values:
if (value == -5000) { return }
It didn't ever compare equal. (But the program ran with no
thrown errors.) So I changed it to:
if (value == -5000.0) { return }
and it worked.
The lack of any error indication that the first test was wrong
is worrying for a language that was designed to be relatively "safe".
Cheers - Bill
-----------------------------------------------------------------------
Bill Frantz | I like the farmers' market | Periwinkle
(408)356-8506 | because I can get fruits and | 16345
Englewood Ave
www.pwpconsult.com | vegetables without stickers. | Los Gatos,
CA 95032