mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 11:21:15 -03:00
math: Add --base option
Currently a bit limited, unfortunately printf's `%a` specifier is absolutely unreadable. So we add `hex` and `octal` with `0x` and `0` prefixes respectively, and also take a number but currently only allow 16 and 8. The output is truncated to integer, so scale values other than 0 are invalid and 0 is implied. The docs mention this may change.
This commit is contained in:
@@ -173,3 +173,16 @@ math 'log(16'
|
||||
# CHECKERR: math: Error: Missing closing parenthesis
|
||||
# CHECKERR: 'log(16'
|
||||
# CHECKERR: ^
|
||||
|
||||
math --base=16 255 / 15
|
||||
# CHECK: 0x11
|
||||
math -bhex 16 x 2
|
||||
# CHECK: 0x20
|
||||
math --base hex 12 + 0x50
|
||||
# CHECK: 0x5c
|
||||
math --base octal --scale=0 55
|
||||
# CHECK: 067
|
||||
math --base notabase
|
||||
# CHECKERR: math: 'notabase' is not a valid base value
|
||||
echo $status
|
||||
# CHECK: 2
|
||||
|
||||
Reference in New Issue
Block a user