Connect symbols to numbersLesson 46 of 48 · 8 min

Precision starts with the input

Construct high-precision decimal inputs before irreversible low-precision evaluation.

Maths refresher: Significant information

An input representation carries a finite amount of information. Extra output digits cannot recover digits discarded earlier.

0.1=110exactly as a decimal, but not exactly in binary floating point0.1=\frac1{10}\quad\text{exactly as a decimal, but not exactly in binary floating point}
Worked example

Float("0.1",50) starts from decimal text at the requested precision. Float(0.1,50) starts from the already rounded Python float.

Maths prerequisite map ↗

Requesting more digits does not manufacture information that an input has already lost. A Python float such as 0.1 is an approximate binary number. Passing it to a high-precision constructor preserves that already-rounded value with additional representation, rather than recovering an exact decimal tenth.

Input construction comes first
  1. Exact mathematical tenth
    Rational⁡(1,10)=110\operatorname{Rational}(1,10)=\frac1{10}
  2. Python float error
    float⁡(0.1)−110≈5.55×10−18\begin{gathered}\operatorname{float}(0.1)-\frac1{10}\\\approx5.55\times10^{-18}\end{gathered}
  3. Decimal text input
    Float⁡(“0.1”,50)\operatorname{Float}(\text{“0.1”},50)
Starter reference. Extra precision applied after a Python float retains its earlier rounding. A decimal string avoids that initial conversion but still creates a finite-precision value.

A decimal string can specify the intended digits directly, while Rational(1,10) expresses an exact mathematical tenth. Choose between them based on what the input means. An instrument’s stated uncertainty still limits an interpretation even if its printed reading has many digits.

Compare errors relative to an exact tenth using fifty-digit arithmetic. This separates input construction from later numerical evaluation. When a formula is sensitive to its inputs, input uncertainty and arithmetic error both deserve explicit checks.

Will Float(0.1,50) and Float("0.1",50) necessarily encode the same fifty-digit value?

Write a prediction (optional)

Written decimal, exact fraction and floating-point values

Select Run Python with the code unchanged.

Tools
About Python

Python and the course packages can load while you read. Each run starts with fresh user variables; imported modules stay loaded. Stop replaces the worker. Runtime details ↗

Ctrl+Enter or ⌘+Enter runs Python.

Compare with the worked example

Executed from the published Python during the site build. Your own run appears above. Build environment ↗

From Python float
0.10000000000000000555111512312578270211815834045410.1000000000000000055511151231257827021181583404541
From decimal text
0.10.1
Python-input error
5.55111512313⋅10−185.55111512313 \cdot 10^{-18}
Text-input error
00
Exact decimal fraction
110\frac{1}{10}
Worked text output
From Python float: 0.10000000000000000555111512312578270211815834045410
From decimal text: 0.10000000000000000000000000000000000000000000000000
Python-input error: 5.55111512313E-18
Text-input error: 0
Exact decimal fraction: 1/10

Read the starter result

Both Float rows have 50-digit arithmetic. Python-input error measures the difference after starting with a rounded binary float. Text-input error measures the difference after starting with the written decimal. Exact decimal fraction supplies the common reference.

Edit and compare

Replace python_input = 0.1 with python_input = 0.12345678901234567890 and decimal_text = "0.1" with decimal_text = "0.12345678901234567890". Select Run Python. Compare Python-input error and Text-input error against the exact decimal fraction.

Return to the editor

Scope. Arbitrary precision addresses arithmetic representation, not unknown measurement errors or an incorrect mathematical model.

Try a fresh case

What is the best way to preserve a supplied long decimal literal for high-precision arithmetic?

Choose an answer
Need a hint?
Hint 1

Identify the first irreversible rounding step.

Hint 2

Keep the original digits as text until constructing the high-precision number.

Your notesNotes save in this browser when storage is available.