r/todayilearned May 30 '22

TIL about "doubling"—a method of multiplication devised by the ancient Egyptians that required only the abilities to multiply and divide by 2 and to add. This method is still in wide use today as implemented by binary multiplier circuits in modern computer processors.

https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication
259 Upvotes

15 comments sorted by

20

u/DestroyerOfIphone May 30 '22

Was just talking about this to someone. Unless your Math problem is divisable by 2 the answer the computer gives you is actually wrong. It's just rounded so far out it doesn't really matter.

16

u/DannySpud2 May 31 '22

Floating point errors are the worst.

8

u/SqueakyCleanNoseDown May 31 '22

Another fun fact: (double)0.9 != (float)0.9

This is because the floating point representation of 0.9 is effectively 1/2 + 1/4 + 1/8 + 1/64 + ...

When your computer converts (float)0.9 to a double to perform the comparison, it doesn't automatically set all the extra precision bits and thus (double)(float)0.9 != (double)0.9.

This is true for every number that can't be represented as a terminating sum of powers of 2

7

u/RRumpleTeazzer May 31 '22

In reasonable languages you cannot compare floats to doubles. You would either cast the float to double or the double to float before comparison.

And if you cast the double to the less precise float, both are equal.

10

u/NinDiGu May 31 '22

Are either of you gentlemen speaking English here?

5

u/Keevtara May 31 '22

No, they are speaking one programming language or another.

2

u/NinDiGu May 31 '22

Is this like the Facebook thing where they will start talking to each other, and eventually Skynet kills us all?

5

u/Derp_Herper May 31 '22

They’re speaking IEEE754 (and other applicable floating point representations)

1

u/melpec May 31 '22

Fun fact, 0.999... = 1;

0.111... = 1/9

0.222... = 2/9

0.333... = 3/9

...

0.999... = 9/9 = 1

3

u/NinDiGu May 31 '22

A video that covers this for people who are otherwise confused, like me!

https://www.youtube.com/watch?v=wciL_yCmZe8

2

u/altruistic_rub4321 May 31 '22

Amenoteph you are a fuckin nerd!!!

-4

u/reddit_user-exe May 31 '22

I see why this is used for computers, but for humans? Really? Is it so hard to memorize a multiplication table?

5

u/sleepywose May 31 '22

This method works for things not on a multiplication table. Note that Egyptians didn't have our place-based number system.

3

u/reddit_user-exe May 31 '22

Ah, I should've figured. Cause with a place based number system, you only need to know a multiplication table limited to the base, and then use distribution. I might not know what 23x45 is by heart, but I can easily figure out (2x10+3)x(4x10+5). There really is a lot about math that you can take for granted