Four is magic: Difference between revisions

Content added Content deleted
(→‎{{header|UNIX Shell}}: Fix bug in name translation.)
(→‎{{header|UNIX Shell}}: Add support for negative numbers)
Line 3,275:
name_of() {
# return the English name for a numeric value
local -i n=$1
 
if (( n < 0 )); then
printf 'negative %s\n' "$(name_of $(( -n )))"
return 0
fi
 
# Names for numbers that fit in a bash integer
local -A names=([0]=zero [1]=one [2]=two [3]=three [4]=four [5]=five
Line 3,289 ⟶ 3,296:
local powers_of_10=($(printf '%s\n' "${!names[@]}" | sort -nr | grep '00$'))
 
local -i n=$1
# find the largest power of 10 that is smaller than n
local -i i=0