๐งฎ Basic Math Operations
Scripts sometimes need to do math.
randomโ
Generates a pseudo-random number.
Argument | Description |
---|---|
limit | Maximum value (optional). |
ui_print "Random number: $(random)"
ui_print "Random number up to 10: $(random 10)"
calcโ
Performs basic mathematical operations.
Argument | Description |
---|---|
OPS | Operation |
result=$(calc "5 + 5") # Returns 10
result=$(calc "20^45 * (30 / 5)") # Scientific notation
intโ
Converts to an integer without rounding.
Argument | Description |
---|---|
VALUE | Number or operation |
result=$(int "5.5") # Returns 5
result=$(int "(5^3)/2") # Returns 62
floatโ
Converts to a floating-point number.
Argument | Description |
---|---|
VALUE | Number or operation |
setdefault float_length 2
result=$(float "5.5") # Returns 5.50
result=$(float "(5^3)/2") # Returns 62.50
roundโ
Rounds to the nearest integer.
Argument | Description |
---|---|
VALUE | Number or operation |
result=$(round "5.5") # Returns 6
result=$(round "(5^3)/2") # Returns 63