1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 09:53:22 -07:00

function to check for 404s, scrap old math crap

This commit is contained in:
Connor Olding 2014-07-04 22:44:00 -07:00
parent 5723bde17d
commit 5a9019296b

View File

@ -64,40 +64,11 @@ autoload -U zmv
zmodload zsh/mathfunc
autoload -Uz zcalc
# consts are 2^-22 and 2^-21 which are simply representable in IEEE 754 floats
zsh_math_func_slope() {
(( (f($1 + 0.000000238418579) - f($1 - 0.000000238418579))/0.000000476837158 ))
isup() {
curl -sLI -w '%{http_code}' -o /dev/null "$1" | read -r
[ "${REPLY:0:1}" -eq 2 ]
}
zsh_math_func_newton() {
local i y=${1:-0}
for ((i=0; i<${2:-8}; i++)); do
(( y -= f(y)/slope(y) )) || return 1
done
(( y ))
}
zsh_math_func_newton2() {
local i x y=${1:-0} d=999999999 p=$(( 2**-${2:-32} ))
for ((i=0; i<32; i++)); do
(( x = y ))
(( y -= f(y)/slope(y) ))
(( $d < (d = abs(x - y)) )) && {
echo 'error: diverging, no solution' >&2
return
}
(( d < p )) && break
done
[ $i -eq 32 ] \
&& echo "warning: didn't hit precision limit" >&2 \
|| echo "iterations: $i" >&2
(( y ))
}
functions -M slope 1 1 zsh_math_func_slope
functions -M newton 0 2 zsh_math_func_newton
functions -M newton2 0 2 zsh_math_func_newton2
DIRSTACKSIZE=24
dirprev() {
pushd -q +1