Skip to main content

Timeline for When does (x == x+2)?

Current License: CC BY-SA 3.0

15 events
when toggle format what by license comment
Jun 17, 2020 at 9:04 history edited CommunityBot
Commonmark migration
May 3, 2017 at 18:40 comment added Paul R @chux: thanks for the confirmation - that's definitely something I may need to watch out for in future, as much of my code ends up being cross-platform.
May 3, 2017 at 18:39 comment added chux @PaulR Do not use float_t much. C11 §7.12 2 confirms your comment and my printf("%d %zu %zu\n", FLT_EVAL_METHOD, sizeof (float_t), sizeof (long double)); --> 2 12 12 LSNED
May 3, 2017 at 18:35 history edited Paul R CC BY-SA 3.0
added 70 characters in body
May 3, 2017 at 18:33 comment added Paul R @chux: interesting - so are both float_t and double_t typedef'd to long double in that environment ? ("all operations and constants evaluate in the range and precision of long double. Additionally, both float_t and double_t are equivalent to long double")
May 3, 2017 at 18:28 comment added chux @PaulR float x = 1e10; printf("%d %d\n", x == x + 2, FLT_EVAL_METHOD); prints 0 2 on 64-bit PC "gcc version 5.4.0". x = 1e37f; works there as hoped.
May 3, 2017 at 18:26 comment added Paul R @chux: thanks - I wasn't aware of FLT_EVAL_METHOD - out of interest, do you know of any platforms/environments where it's set to something other than 0 ?
May 3, 2017 at 18:21 comment added chux This can readily fail when FLT_EVAL_METHOD == 1 as the math is done as double. Recommend a larger FP value sure to exceed even long double precision like 1.0e37f
Nov 30, 2016 at 15:20 comment added GoatInTheMachine @mbomb007: I also think they're very different - ∞ + 2 = ∞ is something anyone could understand and doesn't depend on anything computer specific, whereas adding 2 to a concrete number and it having no effect is a bit more surprising and specific to the limited precision of computers, and more interesting IMHO
Nov 30, 2016 at 14:55 comment added Paul R @mbomb007: I think they are different - the answer you link to relies on INF + 2 == INF, whereas my answer uses a single precision float which is large enough that 2 is less than one ULP.
Jan 25, 2016 at 15:00 history edited Paul R CC BY-SA 3.0
Add language tag for syntax highlighting
Mar 10, 2014 at 14:16 comment added Tim S. +1 for real-world applications. Too many people don't understand floating point mathematics.
Oct 21, 2012 at 22:35 history made wiki Post Made Community Wiki by PleaseStand
Sep 6, 2012 at 15:35 review Low quality posts
Sep 6, 2012 at 15:45
Sep 6, 2012 at 15:30 history answered Paul R CC BY-SA 3.0