Re: Rounding of the double
- From: "Les" <l.neilson@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 1 Jun 2007 17:07:23 +0100
"Alex" <alsim123@xxxxxxxxxxx> wrote in message
news:1180709515.897443.226890@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Again, everybody, please try to understand what I need, I thought
that I'd expressed myself clear enough. But I will try to do it
again:
1. I don't need the representation of this double.
No, but the computer *does*. This is the whole point.
ALL float and double variables and their associated math operations use the
internal representation in memory, as specified by IEEE
2.0 - 80.0/100.0 involves floating point math operations which may be
inexact.
2. I need to divide 8 by 10 and later on to be able use the result
0.2, not 0.199999999999999999
But obviously C++ won't allow me to do so, because of the nature of
float data type.
It is NOT the fault of C++ or any other compiler.
ALL COMPUTERS DOING FLOATING POINT ARITHMETIC WILL USE APPROXIMATIONS FOR
THOSE VALUES THAT CANNOT BE REPRESENTED EXACTLY IN MEMORY.
0.8 is one of those values.
There are others.
As you have found out, in order to give the result that you require, you
yourself have to handle the numbers in a particular way - using integers in
your case.
Or may be I want too much :)
Only if you expect the computer to produce *exact* math every time.
Les
Thanks,
Alex
.
- References:
- Re: Rounding of the double
- From: Les
- Re: Rounding of the double
- From: Alex
- Re: Rounding of the double
- Prev by Date: Re: Rounding of the double
- Next by Date: Re: How to set focus to the previous app that had it?
- Previous by thread: Re: Rounding of the double
- Next by thread: Re: Rounding of the double
- Index(es):
Relevant Pages
|