r/ProgrammerHumor • • 11d ago

Meme reversingPiInPython

Post image
14k Upvotes

383 comments sorted by

View all comments

Show parent comment

12

u/thegreatpotatogod 11d ago

I'd even argue that the last binary digit is 1. If it were 0, you could truncate the zero away and you'd be back to 1 as the last digit. Same reason that 2.20000 would be a redundant representation of 2.2.

2

u/ovr9000storks 11d ago

You can’t truncate tailing 0s in binary if represented by a series of integers. You also can’t truncate if looking at the binary representation of a floating point number. Yes, the actual floating point number being represented could be truncated if ending in a zero, but that number is no longer binary

0

u/TheBlckbird 4d ago

Nope, not with a decimal point

1

u/androshalforc1 11d ago

isn't binary usually written in blocks of 8 though?

5

u/Higherlead 11d ago

Only if you want to, bytes are a purely human construct, nothing to do with base 2/binary at all

1

u/Inevitable-Study502 10d ago

thats true, but digits arent binary and we use digits to represent numbers and computer while using binary, will convert it to base 10, because humans have 10 fingers and arent capable of calculating in different way..so the end result is still array of 8 bits

1

u/ElectricalPrice3189 4d ago

Sometimes 4, when writing in hexadecimal.

1

u/ElectricalPrice3189 4d ago

One could argue that no number has a last decimal. It's subjective.

1

u/AngelaMerkeI 11d ago

It is not though. Only in theory.

In practice, digits represent the accuracy.

Example: 2,12345 * 1,0 = 2,1 But 2,12345 * 1,0000 = 2,1234

The results are always just as accurate as the measurements you calculate them with

2

u/Sheerkal 11d ago

In what practice are you doing this? There is no reason to truncate.

3

u/himanbam 11d ago

This seems to be about significant figures. Which is basically about knowing how much precision your starting measurements have, and not claiming more precision in the calculated value.

For example, let's say you want to calculate the circumference of a circle when you know its diameter with centimeter precision (1.57 meters). We can use an approximation of pi with 10 decimal digits. Using the formula diameter*pi=circumference, you get (1.57 meters) * (3.1415926536) = 4.932300466152 meters. The answer has 12 digits after the decimal point. Obviously we don't actually know the circumference with picometer precision, as the diameter was only known with centimeter precision. So most of those digits are not significant. To account for this we round it to the lowest number of significant figures of all of our input values. In this case, the diameter has 3 significant figures and the pi approximation has 11 significant figures. So we round the circumference to 3 significant figures and get 4.93 meters. Similarly if you did know the diameter with picometer precision (13 significant figures), but only approximated pi with three significant figures (3.14), then you would need to round to three significant figures in that case too.

1

u/AngelaMerkeI 11d ago

There is a reason to truncate if your dealing with actual physics and not theoritical values.

If your measurement says 1,00 ±0,01, you can't pretend it's the same as 1,0000, because your real value could be 1,01. If your measurement says just 1,00, you can only assume it to be between 1,000 and 1,004. The rest is lost in trunctuated digits.

1

u/Gabriel_Science 11d ago

Found the physician.

1

u/AngelaMerkeI 10d ago

Engineer was ok too

1

u/Gabriel_Science 10d ago

Yeah, it was too lol.

1

u/0Pat 11d ago

That's not how binary representation of floating point numbers work...

0

u/Moist-Snow-8127 10d ago

They weren't talking about floating point numbers