Home / Docs / Standard library / Prelude
abs
Release v0.4.0Edition 0.1 and later
A function of the prelude, in scope in every module. Edition 0.1 and later.
una
pub abs(x: Int) -> Int
ensures result >= 0 and (result == x or result == -x)The absolute value of x (spec/14 §1).
Parameters
x: the number
Returns
Int: the absolute value of x: at least 0, and either x or -x.
See also
Example
src/shop.una
module shop
--- How far a counted stock is from the book stock, either way.
pub main() -> Unit
uses @console: Console[print]
=
let gap = abs(18 - 21)
@console.print("off by {gap}")una run . prints:
Output
off by 3Specification
Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.