0
$\begingroup$

Why the following calculation gives Indeterminate value?

a = 4.248354255291589`*^-18;
b = -4.248354255291589`*^-18;
c = 1.3956025592769147`*^18;
X = a + c
Y = b + c
Z = X - Y
Z Log[Z]

(*1.3956*10^18
1.3956*10^18
0.
Indeterminate*)

I know that 0*Log[0]is Indeterminate value, but the question is why X is equal to Y even though "a" is not equal to "b"?

$\endgroup$
5
$\begingroup$

You have X=Y=c because a and b are 10^36 smaller than c and the machine precision is 10^-15.

Here you are working in machine precision (a machine precision number has nothing after the `)

It is possible to work with a higher precision, for example 40 digits:

a= 4.248354255291589`40*^-18
b = -4.248354255291589`40*^-18
c = 1.3956025592769147`40*^18
X = a + c
Y = b + c
Z = X - Y
Z Log[Z]t  

4.248354255291589000000000000000000000000*10^-18
-4.248354255291589000000000000000000000000*10^-18
1.395602559276914700000000000000000000000*10^18
1.395602559276914700000000000000000004248*10^18
1.395602559276914699999999999999999995752*10^18
8.497*10^-18
-3.340*10^-16

EDIT

It is possible to mix different precisions, for example 4 digits for a and b and 40 for c :

a = 4.248354255291589`4*^-18
b = -4.248354255291589`4*^-18
c = 1.3956025592769147`40*^18
X = a + c
Y = b + c
Z = X - Y
Z Log[Z]  

4.248*10^-18
-4.248*10^-18
1.395602559276914700000000000000000000000*10^18
1.395602559276914700000000000000000004248*10^18
1.395602559276914699999999999999999995752*10^18
8.50*10^-18
-3.340*10^-16

But, as soon as there is a machine precision number somewhere , the whole calculus is done in machine precision. So this doesn't work :

a = 4.248354255291589`*^-18
b = -4.248354255291589`4*^-18
c = 1.3956025592769147`40*^18
X = a + c
Y = b + c
Z = X - Y
Z Log[Z]  

4.24835*10^-18
-4.248354255291589000000000000000000000000*10^-18
1.395602559276914700000000000000000000000*10^18
1.3956*10^18
1.395602559276914699999999999999999995752*10^18
0.
Indeterminate

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.