nus-cs2103-AY1920S1 / forum

Forum
1 stars 1 forks source link

💡Unit Testing Floating Point Numbers #147

Open uggi121 opened 5 years ago

uggi121 commented 5 years ago

As a direct consequence of the IEEE 754 format for floating point numbers, it is impossible to achieve 100% accuracy and precision in testing floating point values. A pragmatic heuristic to follow involves factoring in the inputs to the method and padding the expected return value with a suitable error threshold.

For example, 0.1 + 0.2 is not equal to 0.3 in this format. Keep this in mind while designing unit tests and choose an appropriate error tolerance range. Another good practice for mathematical methods is to test them against similar existing implementations