On 2015-09-09 05:19 PM, Constantine Yannakopoulos wrote: > On Wed, Sep 9, 2015 at 4:54 PM, Igor Tandetnik <igor at tandetnik.org> wrote: > >> A comparison like this would not generally be a proper collation. The >> equivalence relation it induces is not transitive - it's possible to have A >> == B and B == C but A != C (when A is "close enough" to B and B is "close >> enough" to C, but A and C are just far enough from each other). >> > ?Out of curiosity, doesn't this also apply also to numeric (real number) > comparisons since SQLite3 uses IEEE floating point arithmetic??
IEEE Float comparisons do not work this way - you are more likely to find the opposite: two numbers that seem to be near perfectly equal might fail an equality test. Such confusion might be caused by statements such as: ...WHERE (5.6 - 3.1) = 2.5 ...WHERE (14 * 0.4) = 5.6 Which might return false if two or more of the constants cannot be precisely represented. (The second one is a known problem value). Nothing however would "seem" equal to the processor if they are not exactly equal in binary form - no "almost" matching happens. BTW: In strict Math it can be shown that 0.999... (repeating) is exactly equal to 1 but in IEEE floats they are not, but that is just because an 8-byte (64b) float lacks the capacity to render the repeating nines to sufficiently wide a representation to find the one-ness of it. https://en.wikipedia.org/wiki/0.999... IEEE fun in C#: Testing 1/3: f = 0.3333333 d = 0.333333333333333 m = 0.3333333333333333333333333333 f*3 = 1 d*3 = 1 m*3 = 0.9999999999999999999999999999 (double)f*3 = 1.00000002980232 (decimal)f*3 = 0.9999999 (decimal)d*3 = 0.999999999999999 (double)((float)i/3)*3 = 1 Testing 2/3: f = 0.6666667 d = 0.666666666666667 m = 0.6666666666666666666666666667 f*3 = 2 d*3 = 2 m*3 = 2.0000000000000000000000000001 (double)f*3 = 2.00000005960464 (decimal)f*3 = 2.0000001 (decimal)d*3 = 2.000000000000001 (double)((float)i/3)*3 = 2 Cheers, Ryan