Your Twelfth Day in C (Floating Point Comparison) - Crash Course in C Programming

preview_player
Показать описание

►Lesson Description: In this lessons I show one of the key problems in programming, regardless of programming language--floating point comparison error! Unfortunately, computers cannot represent every possible number, so floating point (whether single or double precision) provides a close enough approximation for most use cases. However, some numbers (e.g. 1/3) or after a series of mathematical operations (i.e. lots of multiplications of floating point numbers) may cause imprecision to accrue. In order to deal with this, we often use an epsilon value to approximate if two floating point numbers are equal when performing a comparison.

00:00 Introduction
00:31 Demonstration of floating point precision
2:06 Floating point comparison error with == operator
3:52 Trying to add more precision with a double
4:50 Using 'fabs' and an epsilon value to check for equality
7:30 Wrap up

►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

the idea of using a tolerance when comparing two floating point numbers is also commonly used when converting code between different architectures

rzwnhmd
Автор

Thank you for the quick wonderful video.

dhanushs
Автор

To be fair even in real world we still have to deal with tolerance

haroldcruz