Administrator
|
The subject pretty well says it all.
-- One would expect the following expression to answer 'true'. It doesn't. 1000.0e171 = 1.0e174 (There is a discrepancy in the least significant bit.) You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Hi Richard,
-- We will take a look at this and report back. Thanks. -- Seth On Wednesday, February 26, 2014 2:12:39 PM UTC-5, Richard Sargent wrote:
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
In reply to this post by Richard Sargent
Richards -
-- While I agree that it appears that this expression should answer true when evaluated, you should not count on it doing so. Floating point values are inherently inaccurate because they are approximations. Looking at EsScanner>>#readNumber, I see that the exponent is turned into an Integer (or, in this case, a LargeInteger) by sending it #powerOfTen. So what we really have is: 1.0 * (174 powerOfTen asFloat) = 1000.0 * (171 powerOfTen asFloat) Since there are floating point operations involved in this comparison, you can get lucky (the values are exactly representable as Floats) or unlucky (the values are not exactly representable as Floats) -- you got unlucky. Also notice that: 1.0e171 * 1000.0 = 1000.0e171 answers true. In this case there is no uncertainty associated with the exponent since both sides use the same exponent. So, the message is: "Don't use = with Floats" because you will get unexpected results. On Wednesday, February 26, 2014 2:12:39 PM UTC-5, Richard Sargent wrote:
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Richard -
-- Of course, EsScanner>>#readNumber could normalize the number before applying the exponent and the problem would be corrected, but it doesn't. Just for a point of comparison, VW 7.9.1 answers false for 1.0d174 = 1000.0d171, and Pharo 2 answers true for 1.0e174 = 1000.0e171 (probably because it uses a different internal representation for Floats), so there is no consistency among the 3. John On Monday, March 3, 2014 3:38:17 PM UTC-5, John O'Keefe wrote:
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Free forum by Nabble | Edit this page |