1
0
src/bin/subtract

15 lines
396 B
Plaintext
Raw Normal View History

2022-05-14 18:52:57 -06:00
#!/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