Missing precision
See original GitHub issueI have trouble calculating a relatively simple expression “log(8/(2pi5cos(7/5)^2))(2*5)^(-8)” to the desired precision.
My code
import mpmath as mpm
from mpmath import mpf
mpm.dps = 100; # Target (decimal) precision
# Trying to calculate
mpmmp = mpm.log(8/(2*mpm.pi*5*mpm.cos(7/5)**2))*(2*5)**(-8)
# also tried, but gives the same result:
# mpmmp = mpm.log(mpf(8)/(mpf(2)*mpm.pi*mpf(5)*mpm.cos(mpf(7)/mpf(5))**mpf(2)))*(mpf(2)*mpf(5))**(-mpf(8))
print(N(mpmmp, 50))
# Same thing in Wolfram Alpha https://www.wolframalpha.com/input?i=+log%288%2F%282*pi*5*cos%287%2F5%29%5E2%29%29*%282*5%29%5E%28-8%29
wamp = mpm.mpf("2.1764268381757881245184989320757924235425037995295963369536875540976739004791583229859268345586450088673471866819775813945E-8")
print(N(wamp, 50))
print(N(mpmmp-wamp, 50))
With the result
0.000000021764268381757866721875713136684360460293419237132
0.000000021764268381757879956765513985127158402832492356538
-1.3234889800848442797942539073119405657052993774414e-23
Why do they not match?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Format specifier missing precision error with string formatting
There is a small mistake in your format string: 'Converted: {:.lf}'. should be 'Converted: {:.1f}'. The only difference is that you have ...
Read more >ValueError: Format specifier missing precision Python
ValueError: Format specifier missing precision Python ... To print the floating point numbers, you have to have atleast one of the inputs as...
Read more >How to control decimal precision? : r/learnpython - Reddit
I get an error that states 'ValueError: Format specifier missing precision' # Find PI to the Nth Digit import math num = float(input("Enter ......
Read more >Losing My Precision: Tips For Handling Tricky Floating Point ...
Loss of precision in converting into floating point; Adding numbers of very different magnitudes; Subtracting numbers of similar magnitudes; Multiplying and ...
Read more >time - Is there concurrency or is it just missing precision? - Physics ...
Imagine I measure the time of two balls hitting the ground. My stopwatch displays 5.5 seconds for both of them. Then I could...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, the “mpm.mp.dps = 100” solved it!
So many hours of frustration this has solved! Many Thanks!
Sorry! I guess I skimmed the rest after seeing the mistakes in the code that is not commented out.
The problem is this line:
It should be