mirror of https://dicksdeathabove.xyz/~mia/sh.sqrt
|
||
---|---|---|
babylonian | ||
fc@17970dcb75 | ||
math@e8124ffad9 | ||
miterate | ||
miterate.dec | ||
ran@339a95dc70 | ||
.gitmodules | ||
LICENSE | ||
README |
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