0
$\begingroup$

I have problem in Mathematica with unnecessary rounding which is caused by high precision. For example I have value a = 2.052685846*10^-1865, when I make b = 1 - a the result is b == 1.
What can I do to have a better precision, without rounding?

$\endgroup$
4
  • 1
    $\begingroup$ Works for me, but I'm on 9.0.1. Don't imagine any major differences here between versions - are your examples exactly what you're using? $\endgroup$
    – ciao
    Mar 21, 2014 at 9:04
  • $\begingroup$ @rasher Yes, it is EXACTLY the same. So as you can see, there must be a difference. Or maybe I can change seetings to have better precision? $\endgroup$
    – Ziva
    Mar 21, 2014 at 9:12
  • $\begingroup$ Are you sure you didn't write b = 1. - a? The decimal point after the 1 makes all the difference. $\endgroup$
    – m_goldberg
    Mar 21, 2014 at 16:32
  • 1
    $\begingroup$ Considering Mr.Wizard's answer, I don't think this question should be closed. $\endgroup$
    – Michael E2
    Mar 22, 2014 at 1:35

2 Answers 2

2
$\begingroup$

Works for me on Mathematica 8.0.
however, you can try using N to have the value number with the number of significant digits as you like:

b = N[ 1-a, 2000]

$2000$ digits after the decimal point in this case Mathematica does not perform rounding to $1$.

$\endgroup$
1
  • $\begingroup$ @Ziva N[ 1-a, 2000] yields the same result as 1 - a for me (V9.0.1, 8.0.4, 7.0.0). I don't get 2000 digitsl I get 1880 plus 27 insignificant digits. $\endgroup$
    – Michael E2
    Mar 22, 2014 at 1:34
2
$\begingroup$

I suspect that there may be an issue of $MaxMachineNumber in play here. On my machine $MaxMachineNumber is 1.79769*10^308 therefore:

MachineNumberQ[a = 2.052685846*10^-1865]

Precision[1 - a]
False

1880.64

This means that 1 - a is done with arbitrary precision arithmetic and all digits are displayed. However if a smaller exponent is used such that a is machine size only machine precision arithmetic will be used, and the result is 1.:

MachineNumberQ[a = 2.052685846*10^-186]  (* note -186 *)

1 - a

Precision @ %
True

1.

MachinePrecision
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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