Author |
Message |
tiedye1
|
Posted: Mon Oct 10, 2011 12:45 pm Post subject: Decimal Persicion Problems |
|
|
Hi.
I made a simple bouncing ball simulation, and I want to go on to make more complicated physics things but before I go on I want to be able to use better precision decimals.
Currently Turing is truncating real numbers to six decimal places, but the documentation say it should have accuracy to 14-16 decimal places. How can increase the number of decimal places.
Your help would be greatly appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Mon Oct 10, 2011 1:09 pm Post subject: RE:Decimal Persicion Problems |
|
|
Multiply values by multiples of 10 until you have the accuracy you need.
12.9872352 isn't gonna math well. But 129872.352 will. |
|
|
|
|
|
tiedye1
|
Posted: Mon Oct 10, 2011 1:12 pm Post subject: Re: Decimal Persicion Problems |
|
|
That could work for division multiplication and stuff, but I forgot to mention I'm using trigonometric functions and they still output decimals limited to 6 decimal places. |
|
|
|
|
|
Tony
|
Posted: Mon Oct 10, 2011 2:58 pm Post subject: RE:Decimal Persicion Problems |
|
|
Is this actually a problem? E.g. if you are wrong on the 6th digit, you'd need to accumulate an error of x100,000 to be off by a single pixel.
If you want to know how floating point numbers (real) work, start reading up on http://en.wikipedia.org/wiki/IEEE_754-2008 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
mirhagk
|
Posted: Mon Oct 10, 2011 7:40 pm Post subject: RE:Decimal Persicion Problems |
|
|
and are you sure it is only using 6 decimal places? It probably is cutting the rest off when it displays it, but the trig functions should have more precision I think. Try multiplying the number by 1 million or something, and see if it still only shows those digits, or if there are new ones now. |
|
|
|
|
|
Insectoid
|
Posted: Tue Oct 11, 2011 10:44 am Post subject: RE:Decimal Persicion Problems |
|
|
However accurate the trig functions are, the calculations will still be broken by inaccurate float division or multiplication (division in particular I think). The only solution in Turing that I know of is powers of ten which I already mentioned. |
|
|
|
|
|
mirhagk
|
Posted: Tue Oct 11, 2011 2:58 pm Post subject: RE:Decimal Persicion Problems |
|
|
floating point math is sometimes very precise, and it's unprecise only in certain scenarios. For instance, if you add 1 to 1 trillion, 1 trillion times, then you won't get 2 trillion (I think). but if you are working with velocity and values that are all going to be within the same range then it will be fine.
(ps insectoid, floating point is just scientific notation). |
|
|
|
|
|
Tony
|
Posted: Tue Oct 11, 2011 5:11 pm Post subject: RE:Decimal Persicion Problems |
|
|
Or you know... things like 0.1 (requires infinite precision for base-2 floating point numbers). |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
tiedye1
|
Posted: Tue Oct 11, 2011 6:08 pm Post subject: Re: RE:Decimal Persicion Problems |
|
|
mirhagk @ Mon Oct 10, 2011 7:40 pm wrote: and are you sure it is only using 6 decimal places? It probably is cutting the rest off when it displays it, but the trig functions should have more precision I think. Try multiplying the number by 1 million or something, and see if it still only shows those digits, or if there are new ones now.
Your right! Turing was just truncating the digits when I displayed them. Does any one know how to display the full decimal? |
|
|
|
|
|
Tony
|
|
|
|
|
mirhagk
|
Posted: Tue Oct 11, 2011 8:05 pm Post subject: RE:Decimal Persicion Problems |
|
|
Yeah but 0.9999699 is close enough to 1 in nearly every application, except when someone is not bright at comparing floating point numbers. If the velocity is 0.9999699 instead of 1, I don't think you would ever notice. |
|
|
|
|
|
|