Hi, how to increase accuracy of float result ? 
July 23rd, 2005, 04:59 AM
| | | |
I mean, when I am trying to get result of 1/3 (or smf) it returns
0.33333333334 or something. I understand that result can not be 100%
right, but it is it possibly to get more accuracy ?
Sincerely,
sidukas | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ? dkultasev@gmail.com wrote:[color=blue]
> I mean, when I am trying to get result of 1/3 (or smf) it returns
> 0.33333333334 or something. I understand that result can not be 100%
> right, but it is it possibly to get more accuracy ?[/color]
Use 'double'. Some platforms have 'long double' different from 'double',
use that. Or you could use some kind of "arbitrary precision" package or
"exact arithmetic" package. Look for those on the web.
V | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
long double doesn't give you accuracy. It increases limits. The limits
of float are enough for me. | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ? dkultasev@gmail.com wrote:[color=blue]
> long double doesn't give you accuracy. It increases limits. The limits
> of float are enough for me.[/color]
Why are you arguing? You asked, I answered. If you don't believe me
(which is fine by me), use other sources of information.
'double' on most systems has at least 16 decimal digits of precision,
while 'float' has only 6. 'long double' (where it is different from
'double') has as many as 31 decimal digits (AIX for example). That
in my book says that by using 'double' you achieve higher accuracy.
The range is immaterial.
V | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
<dkultasev@gmail.com> wrote in message news:1115307475.601215.110430@f14g2000cwb.googlegr oups.com...[color=blue]
>
> long double doesn't give you accuracy.[/color]
No, you misunderstand floating point; double may give you more precision than float, long double may give you more
precision than double.
[color=blue]
> It increases limits. The limits of float are enough for me.[/color]
You may, in addition, get larger limits too. Have a look at the first couple of paragraphs of the article "What Every
Computer Scientist Should Know About Floating-Point Arithmetic": http://docs.sun.com/source/806-3568/ncg_goldberg.html
for a brief intro.
--
Lionel B | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
I am not not arguing. I tried already double and long double but it
didnt give me enough accuracy.
Thanks anyway, I downloaded some exact arithmetic packages, and I hope,
that it will help. (spasibo:))
Sincerely,
sidukas | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ? dkultasev@gmail.com wrote:[color=blue]
> I am not not arguing. I tried already double and long double but it
> didnt give me enough accuracy.[/color]
Could it be that you're judging the "accuracy" it gave you by simply
looking at the output? The default number of digits you get when
outputting a floating point value is 7. See 'setprecision' manipulator
to change that number.
[color=blue]
> Thanks anyway, I downloaded some exact arithmetic packages, and I hope,
> that it will help. (spasibo:))[/color]
It might not help. You need to fix your understanding of accuracy before
you move to a "better" representation.
V | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
I am not looking to results on the screen. The problem is that I have
many operations with 2 float's. And the result supposed to be the same,
and then I am trying to do x=(a-b)/a*100 it gives ~1E-6<x<0.2, that is
not very good. | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
<dkultasev@gmail.com> wrote in message
news:1115308710.007231.155520@f14g2000cwb.googlegr oups.com...
[color=blue]
>I am not not arguing. I tried already double and long double but it
> didnt give me enough accuracy.[/color]
How much accuracy do you want, and why? | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
<dkultasev@gmail.com> wrote in message news:1115309620.673741.52770@o13g2000cwo.googlegro ups.com...[color=blue]
> I am not looking to results on the screen. The problem is that I have
> many operations with 2 float's. And the result supposed to be the same,
> and then I am trying to do x=(a-b)/a*100 it gives ~1E-6<x<0.2, that is
> not very good.[/color]
I'm not entirely sure what you're trying to do (a fuller explanation might help), but my suspicion might be that you're
suffering from "catastrophic cancellation". This can happen when subtracting nearby floating point numbers which suffer
rounding error due to some calculation (a classic example of this is a naive implementation of the solution of quadratic
equations).
Again I urge you to look at: "What Every Computer Scientist Should Know About Floating-Point Arithmetic": http://docs.sun.com/source/806-3568/ncg_goldberg.html
and look at the section "Cancellation".
--
Lionel B | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ? dkultasev@gmail.com wrote:[color=blue]
> I am not looking to results on the screen. The problem is that I have
> many operations with 2 float's. And the result supposed to be the same,
> and then I am trying to do x=(a-b)/a*100 it gives ~1E-6<x<0.2, that is
> not very good.
>[/color]
I think this is covered in the FAQ 5.8.
V | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
I want as much as is it possible. Why? Because my program requaries it.
Sincerely, | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
Thank You,
I can not look here for that moment, because I am not at home, I
downloaded this page and I will take a look at home.
Thanks a lot for everyone. | 
July 23rd, 2005, 04:59 AM
| | | | re: Hi, how to increase accuracy of float result ?
dkulta...@gmail.com wrote:[color=blue]
> long double doesn't give you accuracy. It increases limits. The[/color]
limits[color=blue]
> of float are enough for me.[/color]
Please quote enough of the previous message for context in your
replies. To do so using the Google interface, click on "show options"
and use the Reply shown in the expanded header.
Brian | 
July 23rd, 2005, 05:00 AM
| | | | re: Hi, how to increase accuracy of float result ?
On 5 May 2005 09:26:37 -0700 in comp.lang.c++, dkultasev@gmail.com
wrote,[color=blue]
>I want as much as is it possible. Why? Because my program requaries it.[/color]
Then your program is badly designed. You are not going to be happy
until you fix it to work with a _realistic_ degree of accuracy in your
floating point arithmetic, as all such programs that work are
designed. The answer does not lie in more accurate floats, because
there is no such thing as "as much as is possible."
But, if you are using "float" you should quickly switch to "double". |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|