mirror of https://dicksdeathabove.xyz/~mia/sh.sqrt
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

5 months ago  

babylonian  10 months ago  
fc@17970dcb75  5 months ago  
math@e8124ffad9  5 months ago  
miterate  10 months ago  
miterate.dec  5 months ago  
ran@339a95dc70  10 months ago  
.gitmodules  5 months ago  
LICENSE  5 months ago  
README  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
 pshfractional 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 pshprng 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 pshfc and pshfractional; 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