# math question

Questions about MultiCharts and user contributed studies.
arnie
Posts: 1590
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 479 times
Been thanked: 509 times

### math question

I was never a math enthusiastic so I apologise for this question :

Can we multiply by 0.333333 instead of divide by 3.
I want to avoid the division by zero error, and since I'm multiplying by a fixed value, I was hoping that this could resolve the problem.

TJ
Posts: 6868
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 984 times
Been thanked: 1976 times
cautious programmers always use multiplication when possible...

I use *0.5 instead of /2.

*0.33 is just as good as /3 for most situations.

ps.
a side benefit: multiplication is a faster operation than division.
if there is a computer scientist out there, please confirm if this is true.

arnie
Posts: 1590
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 479 times
Been thanked: 509 times
thanks TJ

I did a couple of tests and the results were more accurate when multiplied by 0.333333 than 0.33

TJ
Posts: 6868
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 984 times
Been thanked: 1976 times
thanks TJ

I did a couple of tests and the results were more accurate when multiplied by 0.333333 than 0.33

that would be more accurate for sure,
but if I have to deal with precision at that level,

arnie
Posts: 1590
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 479 times
Been thanked: 509 times
but if I have to deal with precision at that level...

me and my perfectionism...

for me, things must be equal to the cent, otherwise, is not the same thing

SP
Posts: 448
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 280 times

janus
Posts: 758
Joined: 25 May 2009
Has thanked: 42 times
Been thanked: 86 times

### Re: math question

I was never a math enthusiastic so I apologise for this question :

Can we multiply by 0.333333 instead of divide by 3.
I want to avoid the division by zero error, and since I'm multiplying by a fixed value, I was hoping that this could resolve the problem.

How does this avoid the division by zero error? If you are using a variables as follows:

a = x/b;

and you wanted to avoid a division of zero with b = 0 then using multiplication will not make any difference. Reason is to convert the above to a multiplication you would have:

a = x * reciprocal(b);

Guess what? When b = 0 then you still get a division by 0 error. The only way to avoid the error is to have a test as follows:

if b <> 0 then begin
a = x/b;
end else begin
do something else and/or print a warning message and/or alert and/or halt
"something else" could be setting "a" to a very large value, such as:
a = 100000000;
but that depends on the subsequent use of the variable "a".

end;