2020-12-29 08:38:07 -08:00
|
|
|
#!/usr/bin/env zsh
|
2024-07-22 05:28:58 -07:00
|
|
|
# compat: +ash +bash +dash +zsh
|
2021-07-29 05:44:12 -07:00
|
|
|
|
|
|
|
# though technically compatible with other shells,
|
|
|
|
# extra functionality is through zsh's extended arithmetic functions.
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-07-30 17:57:08 -07:00
|
|
|
arith() { ### @-
|
|
|
|
### perform arithmetic using the shell and display the result.
|
2021-08-01 07:33:28 -07:00
|
|
|
### see also [`hex`](#hex) and [`bin`](#bin).
|
2021-08-01 09:45:19 -07:00
|
|
|
### this example requires zsh:
|
2021-08-01 07:33:28 -07:00
|
|
|
###
|
|
|
|
### ```
|
|
|
|
### % db=6
|
|
|
|
### % noglob arith 10**(db/20.)
|
|
|
|
### 1.9952623149688795
|
|
|
|
### ```
|
2021-07-29 05:44:12 -07:00
|
|
|
# <<<"$(($@))"
|
|
|
|
printf "%s\n" "$(($@))"
|
2021-07-29 00:37:35 -07:00
|
|
|
}
|
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || arith "$@"
|