Skip to content

Commit 8ebc9fc

Browse files
committed
refactor: math::calculate
Modified math calculations to prioritize shell arithmetic for integers, falling back to awk only when decimals are needed
1 parent 328d9ca commit 8ebc9fc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/math.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
function math::calculate() {
44
if dependencies::has_bc; then
55
echo "$*" | bc
6-
elif dependencies::has_awk; then
6+
elif [[ "$*" == *.* ]] && dependencies::has_awk; then
7+
# Use awk for floating point calculations when bc is unavailable
78
awk "BEGIN { print ($*) }"
89
else
10+
# Fallback to shell arithmetic which has good integer precision
911
local result=$(( $* ))
1012
echo "$result"
1113
fi

0 commit comments

Comments
 (0)