Re: Trouble with a double
From: VisionSet (spam_at_ntlworld.com)
Date: 04/19/04
- Next message: Stuart Leonard: "Unique "logical" identifier for an object?"
- Previous message: xEM: "String from ByteBuffer"
- In reply to: Princess Morgiah: "Trouble with a double"
- Next in thread: Bryce (Work): "Re: Trouble with a double"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Stuart Leonard: "Unique "logical" identifier for an object?"
- Previous message: xEM: "String from ByteBuffer"
- In reply to: Princess Morgiah: "Trouble with a double"
- Next in thread: Bryce (Work): "Re: Trouble with a double"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|