Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, kzhao, alibaba, 7th_zorro), 650 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
var precision #312506
02/25/10 09:12
02/25/10 09:12
Joined: Feb 2010
Posts: 68
mireazma Offline OP
Junior Member
mireazma  Offline OP
Junior Member

Joined: Feb 2010
Posts: 68
Sorry to ask this here but I've searched on wikipedia and on the web and couldn't find an explanation. I didn't know where to ask math related questions so If I'm wrong please direct me.
In the manual it says about var precision; it stores numbers with fixed point, with 3 decimal digits. The minimum step is 0.001. Isn't this (3) its precision expressed in decimal places?
In the table it says "~9". I'm confused.
And related to this, can somebody explain about this:
Quote:
a multiplication by 100 has an inaccuracy of 0.001/100 = 0.001%, while the result of a division by 0.01 - mathematically the same - is inaccurate by 0.001/0.01 = 10%!

Which of the 3 values (at least) has to be of type "var" for the above to be true? I mean in an assignment like
z = x / y;


ERROR in communism.cpp, line 0:
#include<god.h>
was fatally missed.
Re: var precision [Re: mireazma] #312508
02/25/10 09:22
02/25/10 09:22
Joined: Oct 2009
Posts: 110
Porto-Portugal
Elektron Offline
Member
Elektron  Offline
Member

Joined: Oct 2009
Posts: 110
Porto-Portugal
Use float instead or for better precision double.
Var is fixed point, so if the number is small the precison decrease.
I hope it helps

Cheers
Carlos Ribeiro aka Elektron


Carlos Ribeiro aka Elektron
Check my blog: http://indiegamedeveloper71.wordpress.com/
Re: var precision [Re: mireazma] #312513
02/25/10 10:38
02/25/10 10:38
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Originally Posted By: mireazma
Which of the 3 values (at least) has to be of type "var" for the above to be true? I mean in an assignment like
z = x / y;


dz = sqrt((x / y^2 * dy)^2 + (dx / y)^2)

but i think the manual neglects the latter term, so only y has to be of type var.

by the way, if you want to calculate the error you get for your calculation, use gaussian error propagation: for this example the calculation looks as follows:
let x be arbitrary, dx = 0, dy = 0.001, we want to multiply x by 100.
(1) x' = x / y where y = 0.01; then
dx' = x / y^2 * dy
dx'/x' = dy / y = 0.001 / 0.01 = 0.1

(2) x' = x * y where y = 100; then
dx' = x * dy
dx'/x' = dy / y = 0.001 / 100 = 0.00001

multiplication with 100 has an inaccuracy of 0.001%, which makes sense. division by 0.01 has an inaccuracy of 10%.

Re: var precision [Re: Joey] #312603
02/25/10 16:50
02/25/10 16:50
Joined: Feb 2010
Posts: 68
mireazma Offline OP
Junior Member
mireazma  Offline OP
Junior Member

Joined: Feb 2010
Posts: 68
Thank you.
@Elektron:
float is a versatile type; but I don't think I'll count on it to use it for all the range it is capable of in the same variable. In situations where precision is crucial, like coords I was thinking of reducing the accuracy, in terms described at
wikipedia - accuracy vs. precision
and snap the values (round them).

@Joey:
d means precision in no of decimals, right? It takes me some time to digest it laugh Please say which one is true: A or B:
Supposing both of the operands are of type var
A. Either you multiply or divide, the inaccuracy of the result is the same and raises with no of decimals of the operands. Or
B. The result of a multiplication of any operands has a greater accuracy than the division of the same operands.
From what I understood I tend to say that A is true. In the formula you wrote first, dz doesn't depend on a type of operation between x and y.

Last edited by mireazma; 02/25/10 16:55.

ERROR in communism.cpp, line 0:
#include<god.h>
was fatally missed.
Re: var precision [Re: mireazma] #312631
02/25/10 18:24
02/25/10 18:24
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
d means the error, but that's quite the same as what you said...
and neither A nor B is correct. imagine the case that you want to divide a by 1000.
(1) c = a * b, where b = 0.001, then
dc / c = db / b = 1
(2) c = a / b, where b = 1000, then
dc / c = db / b = 0.0000001

now compare this with the sample from above. there the multiplication was better. here your multiplication leads to an uncertainty of 100% (!).

the general formula to calculate the error propagation is



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1