[Binari] stupid computer

Even though I'm fully aware of these issues using computers, it continues to amase me... ;-) for (double cutoff = 0.0; cutoff <= 1.0; cutoff += 0.05) results in these values for "cutoff": 0.0 0.05 0.1 0.15000000000000002 0.2 0.25 0.3 0.35 0.39999999999999997 0.44999999999999996 etc. Not ending with 1.0, as you'd hope, but with 0.9500000000000003 (right, I know, take an int as loop variable and calculate the double inside the loop, but still ;-)) Sofie

Wow, this sounded so weird i decided to check it myself... and got the same results :/ I think i'm gonna dig through all my code to see if i'm not doing the same thing. *sigh* stupid base 2 computers Michiel Sofie Van Landeghem wrote:
Even though I'm fully aware of these issues using computers, it continues to amase me... ;-)
for (double cutoff = 0.0; cutoff <= 1.0; cutoff += 0.05)
results in these values for "cutoff":
0.0 0.05 0.1 0.15000000000000002 0.2 0.25 0.3 0.35 0.39999999999999997 0.44999999999999996
etc.
Not ending with 1.0, as you'd hope, but with 0.9500000000000003
(right, I know, take an int as loop variable and calculate the double inside the loop, but still ;-))
Sofie
_______________________________________________ Binari Intellectuals Need And Require Insanity https://maillist.psb.ugent.be/mailman/listinfo/binari
-- ================================================================== Michiel Van Bel PhD student Tel:+32 (0)9 331 36 95 fax:+32 (0)9 3313809 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM mibel@psb.ugent.be http://www.psb.ugent.be ==================================================================

Yea, this could create nasty bugs when not aware of the issue.. in my original example the loop runs once less than you'd expect... Sofie Michiel Van Bel wrote:
Wow, this sounded so weird i decided to check it myself... and got the same results :/ I think i'm gonna dig through all my code to see if i'm not doing the same thing.
*sigh* stupid base 2 computers
Michiel
Sofie Van Landeghem wrote:
Even though I'm fully aware of these issues using computers, it continues to amase me... ;-)
for (double cutoff = 0.0; cutoff <= 1.0; cutoff += 0.05)
results in these values for "cutoff":
0.0 0.05 0.1 0.15000000000000002 0.2 0.25 0.3 0.35 0.39999999999999997 0.44999999999999996
etc.
Not ending with 1.0, as you'd hope, but with 0.9500000000000003
(right, I know, take an int as loop variable and calculate the double inside the loop, but still ;-))
Sofie
_______________________________________________ Binari Intellectuals Need And Require Insanity https://maillist.psb.ugent.be/mailman/listinfo/binari
-- Sofie Van Landeghem PhD Student VIB Department of Plant Systems Biology, Ghent University Bioinformatics and Evolutionary Genomics Technologiepark 927, 9052 Gent, BELGIUM Tel: +32 (0)9 331 36 95 fax:+32 (0)9 3313809 Website: http://bioinformatics.psb.ugent.be
participants (2)
-
Michiel Van Bel
-
Sofie Van Landeghem