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.
math question
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: math question
How does this avoid the division by zero error? If you are using a variables as follows: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.
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;
- 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".