1
0

clear out arithmetic apis

This commit is contained in:
dtb 2022-08-13 16:35:26 -04:00
parent 6826b647c3
commit 05954076d2
2 changed files with 0 additions and 40 deletions

26
bin/pow
View File

@ -1,26 +0,0 @@
#!/bin/sh
! eq $# 2 && printf "Usage: $0 [base] [exponent]\n" >/dev/stderr && exit 1
! stris int "$1" && printf -- "%b: %b: Not an integer\n" "$0" "$1" >/dev/stderr && exit 1
! stris int "$2" && printf -- "%b: %b: Not an integer\n" "$0" "$2" >/dev/stderr && exit 1
base=$1
exponent=$2
result=1
while gt $exponent 0; do
result=$(multiply $result $base)
exponent=$(-- $exponent)
done
if ! eq $result $(abs $result) && eq $base $(abs $base); then
printf "$0: Result is unexpectedly negative, possible integer overflow\n" >/dev/stderr && exit 1
elif eq $result 0 && ! eq $base 0; then
printf "$0: Result is unexpectedly zero, possible integer overflow\n" >/dev/stderr && exit 1
else
printf "%b\n" $result
fi
exit 0

View File

@ -1,14 +0,0 @@
#!/bin/sh
# science speak from wikipedia
! eq $# 2 && printf "Usage: $0 [minuend] [subtrahend]\n" >/dev/stderr && exit 1
! stris int "$1" && printf "$0: $1: Not an integer\n" >/dev/stderr && exit 1
! stris int "$2" && printf "$0: $2: Not an integer\n" >/dev/stderr && exit 1
minuend=$1
subtrahend=$2
# (- a b) == (+ a (* b -1))
printf "%b\n" $(add $minuend $(multiply $subtrahend -1))
exit 0