Skip to content

Latest commit

 

History

History
84 lines (57 loc) · 1.77 KB

File metadata and controls

84 lines (57 loc) · 1.77 KB

abs

Returns the absolute value of a number.

Syntax

abs(value)

Parameters

Parameter Type Description
value Number/String The value to get the absolute value of

Returns

String - The absolute value (non-negative) of the input.

Description

The abs function returns the absolute value of a number, which is always non-negative. If the input is negative, it returns the positive equivalent. If already positive or zero, it returns the value unchanged.

Examples

Basic Usage

Result = abs(-5)
// Result: "5"

Result = abs(5)
// Result: "5"

Result = abs(0)
// Result: "0"

Result = abs(-3.14159)
// Result: "3.14159"

With Variables

// Calculate the absolute difference between two values
Difference = abs(Value1 - Value2)
// With Value1=10, Value2=25
// Result: "15"

In Conditional Comparisons

// Check if two values are within a tolerance
IsClose = IF(ABS(Expected - Actual), "LT", Tolerance, "yes", "no")

In Complex Expressions

// Used in the unit tests to verify precision
Result = abs(ComputedValue - ExpectedValue)
// Check if within epsilon: abs(difference) < 0.00000000001

Use Cases

  • Error calculations: Finding the magnitude of differences
  • Distance calculations: Distances are always positive
  • Tolerance checking: Verifying values are within acceptable ranges
  • Data normalization: Converting all values to positive

Related Functions

Notes

  • Uses arbitrary precision arithmetic
  • Returns a string representation of the result
  • Works with the Math service's absPrecise method internally