Qiang Li
Qiang Li

Reputation: 10855

How to do high precision float point arithmetics in mathematica

In Mma, for example, I want to calculate

1.0492843824838929890231*0.2323432432432432^3

But it does not show the full precision. I tried N or various other functions but none seemed to work. How to achieve this? Many thanks.

Upvotes: 2

Views: 921

Answers (3)

Mr.Wizard
Mr.Wizard

Reputation: 24336

Sometimes you just want to see more of the machine precision result. These are a few methods.

(1) Put the cursor at the end of the output line, and press Enter (not on the numeric keypad) to copy the output to a new input line, showing all digits.

(2) Use InputForm as in InputForm[1.0/7]

(3) Change the setting of PrintPrecision using the Options Inspector.

Upvotes: 0

Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57893

When you specify numbers using decimal point, it takes them to have MachinePrecision, roughly 16 digits, hence the results typically have less than 16 meaningful digits. You can do infinite precision by using rational/algebraic numbers. If you want finite precision that's better than default, specify your numbers like this

123.23`100

This makes Mathematica interpret the number as having 100 digits of precision. So you can do

ans=1.0492843824838929890231`100*0.2323432432432432`100^3

Check precision of the final answer using Precision

Precision[ans]

Check tutorial/ArbitraryPrecisionNumbers for more details

Upvotes: 3

Dr. belisarius
Dr. belisarius

Reputation: 61016

You may do:

r[x_]:=Rationalize[x,0];

n = [email protected] ([email protected])^3  

Out:

228598965838025665886943284771018147212124/17369643723462006556253010609136949809542531

And now, for example

N[n,100]  

0.01316083216659453615093767083090600540780118249299143245357391544869\
  928014026433963352910151464006549

Upvotes: 1

Related Questions