Connecting Tech Pros Worldwide Forums | Help | Site Map

Hi, how to increase accuracy of float result ?

dkultasev@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '05
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


Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

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
dkultasev@gmail.com
Guest
 
Posts: n/a
#3: Jul 23 '05

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.

Artie Gold
Guest
 
Posts: n/a
#4: Jul 23 '05

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]
Erm, how to put this succinctly...

Wrong.

--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Victor Bazarov
Guest
 
Posts: n/a
#5: Jul 23 '05

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
Lionel B
Guest
 
Posts: n/a
#6: Jul 23 '05

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

dkultasev@gmail.com
Guest
 
Posts: n/a
#7: Jul 23 '05

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

Victor Bazarov
Guest
 
Posts: n/a
#8: Jul 23 '05

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
dkultasev@gmail.com
Guest
 
Posts: n/a
#9: Jul 23 '05

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.

Andrew Koenig
Guest
 
Posts: n/a
#10: Jul 23 '05

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?


Lionel B
Guest
 
Posts: n/a
#11: Jul 23 '05

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



Victor Bazarov
Guest
 
Posts: n/a
#12: Jul 23 '05

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
dkultasev@gmail.com
Guest
 
Posts: n/a
#13: Jul 23 '05

re: Hi, how to increase accuracy of float result ?


I want as much as is it possible. Why? Because my program requaries it.
Sincerely,

dkultasev@gmail.com
Guest
 
Posts: n/a
#14: Jul 23 '05

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.

Default User
Guest
 
Posts: n/a
#15: Jul 23 '05

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

David Harmon
Guest
 
Posts: n/a
#16: Jul 23 '05

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".

Closed Thread