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.
Float("0.1",50) starts from decimal text at the requested precision. Float(0.1,50) starts from the already rounded Python float.
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.
- Exact mathematical tenth
- Python float error
- Decimal text input
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.
Your saved draft is open. To use the published code, select Restore example in Tools. Use Recover draft to bring back your code.
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.
Execution error
Technical error details
Your result
Python text output
Compare with the worked example
Executed from the published Python during the site build. Your own run appears above. Build environment ↗
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.
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?
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.