sqrt() in pure sh
Go to file
Mia T. Rain d026187aa7
Im insane
2022-06-28 22:19:23 -04:00
babylonian fix babylonian methods average system; add comparison 2022-01-18 02:07:17 -05:00
fc@17970dcb75 Im insane 2022-06-28 22:19:23 -04:00
math@e8124ffad9 Im insane 2022-06-28 22:19:23 -04:00
miterate Added new Mia Method 2022-01-17 23:09:58 -05:00
miterate.dec Im insane 2022-06-28 22:19:23 -04:00
ran@339a95dc70 finish/add babylonian method 2022-01-17 18:45:30 -05:00
.gitmodules Im insane 2022-06-28 22:19:23 -04:00
LICENSE Im insane 2022-06-28 22:19:23 -04:00
README Im insane 2022-06-28 22:19:23 -04:00

README

---
# sh.sqrt
-- Square Root (√) in pure POSIX sh
---- various methods included; see
----- https://en.wikipedia.org/wiki/Methods_of_computing_square_roots 
---
# Status
-- I plan to revamp the Babylonian Method used here to work with decimals
-- psh-fractional should allow for this, however due to size limitations
-- this is on hold as a additional library that can compare floats is needed
---
# Babylonian Method
-- The Babylonian method is the first to be implemented
-- Since sh can only actively work with whole numbers on its own
-- The method is actually quite accurate
-- However (obv) a break down occurs when numbers without 
---- whole Square Roots are inputed, however;
---- the algorithm should/has (have) been adjusted to detect when it 
---- enters and endless loop, and should produce the closest whole number
-- This method requires a starting seed; POSIX sh however lacks $RANDOM
-- thus psh-prng is used by this method; one will have to clone with
---- `--recursive` to pull in the submodule
---
# Mia Method (Miterate)
-- The Mia method works for all numbers >4 with whole digit square roots
-- It works by iterating over every number from 2 -> S/3 until it reaches 
---- the square root of S
-- The square root of 4 has to be hard coded since 4/3 produces
---- 1.333[...] which is < the square root (2)
---
# Mia Method with Decimals (miterate.dec)
-- works with all whole numbers >4
---- square roots of decimals are unlikely to work and are untested
-- can calculate square roots to the 6th decimal place
---- 8 decimal places is possible however you may run into overflow issues
-- It works by usig the original Miterate method 
-- but with a new system to increment decimals
---- It depends on psh-fc and psh-fractional; clone with `--recursive`
---
# Comparison (Babylonian and Miterate)
-- Over 12 iterations; calculating the square root of 144
---- Babylonian Method: 0.1625 seconds (real time)
---- Mia Method: 0.0075 seconds (real time)
-- However it should be noted that that Babylonian Method
---- (when not restricted by sh) can calculate decimal points