Тёмный

LIVE CODING a Square Root Algorithm in VanillaJS 

Подписаться
Просмотров 462
% 13

I woke up with a question: "how the heck do computers calculate the square root?" This video is a fun exercise in trying to write my own square root algorithm. SOURCE CODE below.
- Source Code: github.com/townofdon/square-root-algorithm-js
- Diagrams: whimsical.com/square-root-algorithm-RiiUwd4XAGYjxCXhG6mRSB
After some research, I discovered there are LOTS of alternative algorithms for calculating the square of a number. Even though the math was over my head, I did find some takeaways:
- Bit shift operations are very useful for highly optimized square root calculations
- There exist algorithms that iterate over each number pair in a Base 10 number, meaning the iterations would directly correlate to the number of digits (as opposed to the minimum 60 iterations in my algorithm)
- See: en.wikipedia.org/wiki/Methods_of_computing_square_roots#Decimal_(base_10)
For a cool parallel - check out this video on the fast inverse square calculation found in the Quake engine source code: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-p8u_k2LIZyo.html
For more info about the Early Return Pattern - check out this link: forum.freecodecamp.org/t/the-return-early-pattern-explained-with-javascript-examples/19364

Опубликовано:

 

12 июл 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 3   
@codetyper
@codetyper 2 года назад
Good video👍
@mohammedissam3651
@mohammedissam3651 2 года назад
Great content sub+like I have rough times figuring out the square root of a big numbers what I mean by big is exceeding the maximum number of double & floating types number of digits which is -(2^53 - 1) & 2^53 - 1 About 15 digits The number i seek for is 1 followed by 6 billion zeros which is Ridiculous for many but very important for me. Can you provide me some recommendations about this topic should I use other than js as a programming language ?
@dumbidiot1119
@dumbidiot1119 2 года назад
Maybe a language with more control over your variables. Something more low level than js