math abs

For math.

Returns the absolute value of a number.

Command Type

built-in

Signature

> math abs {flags} ...rest

Parameters

  • ...rest: The cell-paths/columns to operate on.

Input/output types:

input output
number number
duration duration
filesize filesize
list<number> list<number>
list<duration> list<duration>
list<filesize> list<filesize>
range list<number>
record record

Examples

Compute absolute value of each number in a list of numbers.

> [-50 -100.0 25] | math abs
╭───┬────────╮
│ 0 │     50 │
│ 1 │ 100.00 │
│ 2 │     25 │
╰───┴────────╯

Compute the absolute value of list-valued columns in a record.

> {alice: [-1 -2 -3], bob: [-4 -5]} | math abs
╭───────┬───────────╮
│       │ ╭───┬───╮ │
│ alice │ │ 0 │ 1 │ │
│       │ │ 1 │ 2 │ │
│       │ │ 2 │ 3 │ │
│       │ ╰───┴───╯ │
│       │ ╭───┬───╮ │
│ bob   │ │ 0 │ 4 │ │
│       │ │ 1 │ 5 │ │
│       │ ╰───┴───╯ │
╰───────┴───────────╯

Compute the absolute value of a single column using a cell path.

> {alice: [-1 -2 -3], bob: [-4 -5]} | math abs alice
╭───────┬────────────╮
│       │ ╭───┬───╮  │
│ alice │ │ 0 │ 1 │  │
│       │ │ 1 │ 2 │  │
│       │ │ 2 │ 3 │  │
│       │ ╰───┴───╯  │
│       │ ╭───┬────╮ │
│ bob   │ │ 0 │ -4 │ │
│       │ │ 1 │ -5 │ │
│       │ ╰───┴────╯ │
╰───────┴────────────╯

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.