Bash Math Library

We needed a floating point math library for the Bash bundler, so we wrote a very small one, but that means you have access to it when using the bundler.

Functions

Math::Plus

Adds two floats.

result=$(Math::Plus 1.2 3.6)
# 4.8
Math::Minus

Subtracts one float from another.

result=$(Math::Minus 1.2 3.6)
# -2.4
Math::Times

Multiplies two floats.

result=$(Math::Times 1.2 3.6)
# 4.32
Math::Divide

Divides a float by another.

result=$(Math::Divide 1.2 2.43)
# 0.493827
Math::Floor

Floors a float.

result=$(Math::Floor 1.7)
# 1
Math::Round

Rounds a float.

result=$(Math::Round 1.7)
# 2
Math::Mod

Gets the modulus of two floats.

result=$(Math::Divide 3.7 0.3)
# 12.3333333
Math::Abs

Absolute value of a float.

result=$(Math::Abs -9.7)
# 9.7
Math::LT

Tests if one float is less than another.

result=$(Math::LT 1.2 3.7)
# 1
Math::GT

Tests if one float is greater than another.

result=$(Math::GT 1.2 3.7)
# 0
Math::Equals

Tests if one float is equal to another.

result=$(Math::Equals 2.54 2.54)
# 1
Math::Min

Get the minimum of a list of floats.

result=$(Math::Min 3.7 0.3 433 37.2)
# 0.3
Math::Max

Gets the maximum of a list of floats.

result=$(Math::Max 3.7 0.3 433 37.2)
# 433
Math::Mean

Averages a list of floats.

result=$(Math::Mean 3.7 0.3 433 37.2)
# 118.55
Math::hex_to_dec

Converts base16 to base10.

result=$(Math::hex_to_dec 3F)
# 63
Math::dec_to_hex

Converts base10 to base16.

result=$(Math::dec_to_hex 237)
# ED

Questions?

Post on the Alfred Forum thread.

Bug Reports?

Open an issue in the Github queue.