From the course: Faster Python Code
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
When approximation is good enough - Python Tutorial
From the course: Faster Python Code
When approximation is good enough
- [Instructor] Here is a riddle for you. How much is 1.1 times 1.1? Let's see what Python says. So we'll do 1.1 times 1.1. I find the bargain python posts from time to time. A lot of them are similar to what you just saw. Usually applies to RDM failing. Which stands for redefine manual. We send them to read about floating point implementation. It is not the bargain python, if you run the same code in C, Java, Go and other languages, you see the same results. The reason is a design creative. To make floating point calculations fast, some degree of accuracy is sacrificed. Look at the answer, the error is very small. But still, it is an error. As a side note, every time you do testing that involves checking results of floating point numbers, you should allow for some error. Use the built-in round function with the number of digits you think is an acceptable error. What I'm trying to show you that even in something as…