Re: Trouble with a double

From: VisionSet (spam_at_ntlworld.com)
Date: 04/19/04


Date: Mon, 19 Apr 2004 22:41:00 +0100


"Princess Morgiah" <princess_morgiah_nospamplease@yahoo.com> wrote in
message news:n3Xgc.78407$6%5.5262466@phobos.telenet-ops.be...
> Hi everyone,
>
> Why does this
> for (double x = 0.80; x < 1.0; x += 0.01)
> {
> System.out.println("Threshold " + x);
> }
> give me the following result:
> Threshold 0.8
> Threshold 0.81
> Threshold 0.8200000000000001
> Threshold 0.8300000000000001
> Threshold 0.8400000000000001
> Threshold 0.8500000000000001
> Threshold 0.8600000000000001
> Threshold 0.8700000000000001
> Threshold 0.8800000000000001
> Threshold 0.8900000000000001
> Threshold 0.9000000000000001
> Threshold 0.9100000000000001
> Threshold 0.9200000000000002
> Threshold 0.9300000000000002
> Threshold 0.9400000000000002
> Threshold 0.9500000000000002
> Threshold 0.9600000000000002
> Threshold 0.9700000000000002
> Threshold 0.9800000000000002
> Threshold 0.9900000000000002
>
> I can understand that there is a deviation from the expected value, but
why
> not in the first two cases?

Because the error (due to the fact binary cannot represent decimal fractions
accurately) is cumulative and the error initially is not sufficient to
register in the 64 bit representation.

-- 
Mike W


Relevant Pages

  • Re: Green MP
    ... representation, it said to be a problem in Israel "pure" PR system. ... need a threshold percentage, say 10%. ...
    (uk.rec.driving)
  • Re: Barking Dogs in Campgrounds
    ... You know, Mike, you could have pulled out and found another spot ... Bob, is that 10 BPH for all dogs or from just one site? ... See, Mike, questions like that lower my threshold. ...
    (rec.outdoors.rv-travel)
  • Re: Patch[1/2]X86:Adding_Notification_Support_to_therm_throt.c
    ... I am submitting a patch to add core thermal threshold notification ... IA32_THERM_INTERRUPT register. ... This patch is generated against stable Linux-2.6 kernel. ... This patch adds code to therm_throt.c to notify core thermal threshold ...
    (Linux-Kernel)
  • Patch[1/2]X86:Adding_Notification_Support_to_therm_throt.c
    ... I am submitting a patch to add core thermal threshold notification ... IA32_THERM_INTERRUPT register. ... This patch is generated against stable Linux-2.6 kernel. ... This patch adds code to therm_throt.c to notify core thermal threshold ...
    (Linux-Kernel)
  • Patch[1/2]X86:Adding_Notification_Support_to_therm_throt.c
    ... I am submitting a patch to add core thermal threshold notification ... IA32_THERM_INTERRUPT register. ... This patch is generated against stable Linux-2.6 kernel. ... This patch adds code to therm_throt.c to notify core thermal threshold ...
    (Linux-Kernel)