429
you are viewing a single comment's thread
view the rest of the comments
[-] HKPiax@lemmy.world 10 points 1 year ago

I’ve always tried understanding this floating point thing, but I never could. Could anyone here please ELI5?

[-] Rentlar@lemmy.ca 59 points 1 year ago* (last edited 1 year ago)

My ELI5 is this. Pretend you have a robotic pizza cutter, but the only thing it can do with a pizza or pizza slice is cut it in half. If you ask for a tenth of a pizza, well it can give you an 1/8 or a 1/16 by repeatedly cutting a slice.

It can also cut you a 1/16 slice, make 1/32, 1/256, 1/512 and 1/2048 slices separately, shift them together for you and be like: "There. Here's 0.100098 of a pizza. You happy?"

(You can also think of it as the robot cutting the pizza into 2048 slices and mushing together 205 of them to make your "tenth").

[-] HKPiax@lemmy.world 14 points 1 year ago

This is absolutely brilliant. Perfect ELI5, thanks! Would you be so kind to make it so it’s about the binary thing with computers?

[-] Rentlar@lemmy.ca 3 points 1 year ago* (last edited 1 year ago)

Sure I can try to connect the metaphors, in a binary number system you have numbers 1 or 0 to pick from. How it applies in this scenario is that you can only have up to one slice of each size. That works because if you want two of it, you would instead replace it with a one size bigger slice that is equivalent to 2x the smaller size.

For a general understanding of floating point I suggest you learn binary first and separately, because at the end of the day it's just another way to write base-10 numbers. Floating point representation is useful because the basic principle is you pick some fraction that is so small relative to what you're measuring, so you can do most math accurately. (e.g. If I say this dwarf planet is the size of our moon and a 20 tennis balls, the tennis balls don't really change your idea of how big it is)

At the end of the day, FP is like scientific notation but with like 10 significant digits.

[-] soggy_kitty@sopuli.xyz 0 points 1 year ago
[-] Rentlar@lemmy.ca 4 points 1 year ago

I ain't ChatGPT. My comment there kind of sounds like it tho.

[-] ruk_n_rul 3 points 1 year ago

People tend to forget ChatGPT learns from people's comments, like yours.

[-] jana@leminal.space 8 points 1 year ago

Computers are binary, yeah? So we have to represent fractional numbers with binary, too.

In decimal, numbers past the decimal point are 10^-1, 10^-2, ... etc. In binary, they're 2^-1, 2^-2, ....

2^-1 is one half, so 0.1 in binary is 0.5 in decimal. 2^-2 is one quarter. 0.11 in binary is 0.75 in decimal. And of course you've got 0.01 = 0.25

The problem comes when representing decimal numbers that don't have neat binary representations. For instance, 0.1 in decimal is actually a repeating binary number: 0.0001100110011...

this post was submitted on 17 Sep 2023
429 points (96.5% liked)

Programmer Humor

19623 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS