ddonche/goblin-lang
0.46.24
1
0
docs reference
[[abs]]

Abs


abs returns the distance between a number and zero.


Overview

Use abs when you care about the size of a difference, not whether it is positive or negative.

temperature_change | -12
distance_from_zero | abs(temperature_change)

:say(distance_from_zero)  /// 12
temperature_change | -12
distance_from_zero | abs(temperature_change)

:say(distance_from_zero)  /// 12

Positive values stay positive, and zero stays zero:

abs(8)   /// 8
abs(0)   /// 0
abs(-8)  /// 8
abs(8)   /// 8
abs(0)   /// 0
abs(-8)  /// 8


Signature

abs(number)
abs(number)

Argument Type Description
number int, float, pct, or big The number whose absolute value you want.

abs returns the same numeric kind for int, float, and big values. A pct input returns a float.

abs(-14)       /// 14
abs(-2.75)     /// 2.75
abs(pct(-40))  /// 0.4
abs(big(-900)) /// 900
abs(-14)       /// 14
abs(-2.75)     /// 2.75
abs(pct(-40))  /// 0.4
abs(big(-900)) /// 900


Errors

abs requires exactly one argument:

abs()
/// error: R0301 wrong-arity
abs()
/// error: R0301 wrong-arity

Passing a non-numeric value raises a numeric-expected error:

abs("twelve")
/// error: R0200 numeric-expected: abs requires a numeric value
abs("twelve")
/// error: R0200 numeric-expected: abs requires a numeric value