sqrt() in pure sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Mia d026187aa7
Im insane
5 months ago
babylonian fix babylonian methods average system; add comparison 10 months ago
fc@17970dcb75 Im insane 5 months ago
math@e8124ffad9 Im insane 5 months ago
miterate Added new Mia Method 10 months ago
miterate.dec Im insane 5 months ago
ran@339a95dc70 finish/add babylonian method 10 months ago
.gitmodules Im insane 5 months ago
LICENSE Im insane 5 months ago
README Im insane 5 months ago

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