Перейти к содержимому

Why don't we have 'real' type in C/C++?

Axiom Core

0:00 / 0:00

Why don't we have 'real' type in C/C++?

16 просмотров · 2 недели назад
Axiom Core
4 подписчика
16 просмотров · 2 недели назад
Why don't we have a real type in C/C++? This is a complete walkthrough of floating point representation - from the 0.1 + 0.2 demo in C++ all the way down to the IEEE 754 bit layout, explained from the computer architecture level up. We cover: • The 0.1 + 0.2 demo and why cout politely lies to you • Why C++ prints 6 significant digits and rounds the rest away • Fixed-point numbers - the trick behind Doom, Sonic, Street Fighter II and the original PlayStation • How splitting 8 bits into IIII.FFFF works, and why it can't store 0.1 • Enter floating point: letting the decimal point move • How to normalize a floating point number • The IEEE 754 float layout - sign, exponent, mantissa • Floating point error, and why 0.1 can't be stored exactly If you've ever compared two floats with == and watched it fail, this is the video that tells you exactly who to blame. If you're learning C++ and you've hit that moment where your decimals come out wrong and you have no idea why, this is the explanation you were missing. We start with binary floating point basics - how a fixed point representation stores numbers by giving up bits to the integer and fractional halves - then show exactly where it breaks, and why floating point exists as the fix. From there it's a straight line to the standard: the IEEE 754 binary representation, how IEEE 754 conversion works from decimal to IEEE 754 by hand, and how the single precision IEEE 754 format differs from the double precision IEEE 754 format. You'll see the IEEE 754 single precision format laid out bit by bit, plus the floating point arithmetic that goes wrong because of it. By the end you'll understand why floating point error isn't a bug in your code, why 0.1 can't be stored exactly, and what double precision floating point actually buys you over a float. Studying computer organization and architecture? The number systems and binary representation unit is exactly this — the intuition behind the COA formulas, including the binary to decimal conversion you need before any of it clicks. New to programming or picking up C++ for the first time? Start here, then check out the devlog series to see the same fundamentals in action while I build a game development studio from scratch. Leave a comment if you've been bitten by a float comparison - I want to know how bad it got. 00:00 Why does C++ have float and not real? 00:23 The 0.1 + 0.2 demo 01:17 Why cout lies to you 01:43 Fixed-point: how retro games did decimals 04:20 Why fixed-point can't store 0.1 05:27 Enter floating point 05:58 IEEE 754: sign, exponent, mantissa 07:19 The reveal: Why 0.1 can't be stored exactly #floatingpoint #ieee754 #cplusplus #computerscience #gamedev