Chapter 2: Problem 28
Consider the following simple program inspired by Chapter 1.4.3: a = 1/947.0*947 b = 1 if a != b: print ’Wrong result!’ Try to run this example! One should never compare two floating-point objects directly using \(==\) or \(!=\) because round-off errors quickly make two identical mathematical values different on a computer. A better result is to test if \(|a-b|\) is sufficiently small, i.e., if \(a\) and \(b\) are "close enough" to be considered equal. Modify the test according to this idea. Thereafter, read the documentation of the function float_eq from SciTools: scitools numpyutils .float_eq (see page 80 for how to bring up the documentation of a module or a function in a module). Use this function to check whether two real numbers are equal within a tolerance. Name of program file: compare_float.py. 0
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.