mirror of
https://dicksdeathabove.xyz/~mia/psh-fractional
synced 2024-11-08 14:24:15 +00:00
fix addition
This commit is contained in:
parent
b1d01d8ae7
commit
aee9803e50
15
addition/add
15
addition/add
|
@ -4,16 +4,23 @@
|
|||
# modified to check $1 & $2
|
||||
# make sure $1 & $2 are the same length
|
||||
if [ "${#1}" -gt "${#2}" ]; then
|
||||
f2="$2"; until [ "${#f2}" -eq "${#1}" ]; do
|
||||
f2="${2##*.}"; f1="${1##*.}"; until [ "${#f2}" -eq "${#f1}" ]; do
|
||||
f2="${f2}0"
|
||||
done
|
||||
set -- "$1" "$f2"
|
||||
set -- "$1" "${2%%.*}.$f2"
|
||||
elif [ "${#1}" -lt "${#2}" ]; then
|
||||
f1="$1"; until [ "${#f1}" -eq "${#2}" ]; do
|
||||
f1="${1##*.}"; f2="${2##*.}"; until [ "${#f1}" -eq "${#f2}" ]; do
|
||||
f1="${f1}0"
|
||||
done
|
||||
set -- "$f1" "$2"
|
||||
set -- "${1%%.*}.$f1" "$2"
|
||||
fi
|
||||
until [ "${#1}" -ge "${#2}" ]; do
|
||||
set -- "0$1" "$2"
|
||||
done
|
||||
until [ "${#2}" -ge "${#1}" ]; do
|
||||
set -- "$1" "0$2"
|
||||
done
|
||||
#echo "$1 $2"
|
||||
f1="${1##*.}"; f2="${2##*.}" # whole is ${1%.$f1} # dot required
|
||||
# eq is $1+$2 -- $f1 + $f2 -- then add $1 & $2
|
||||
wo="$((${1%.$f1}+${2%.$f2}))" # whole digit, this is preset and not redeclared
|
||||
|
|
Loading…
Reference in a new issue