From ff7bb289745995eae4d898bb4cf0a8ce478fda6b Mon Sep 17 00:00:00 2001 From: CJ <105300705+cjobermaier@users.noreply.github.com> Date: Fri, 16 Aug 2024 15:01:26 -0500 Subject: [PATCH] Update abs.mdx --- website/docs/language/functions/abs.mdx | 31 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/website/docs/language/functions/abs.mdx b/website/docs/language/functions/abs.mdx index 49ceef9c93..8f32aa5d6d 100644 --- a/website/docs/language/functions/abs.mdx +++ b/website/docs/language/functions/abs.mdx @@ -2,14 +2,21 @@ page_title: abs - Functions - Configuration Language description: The abs function returns the absolute value of the given number. --- +# abs function reference +This topic provides reference information about the abs function. The abs function returns the absolute value of the given number. +## Introduction +abs returns the absolute value of the given number. If the number is zero or positive, the function returns the value as-is, but if it is negative, it is multiplied by -1 to make it positive before returning it. -# `abs` Function +## Syntax +Use the abs function with the following syntax: -`abs` returns the absolute value of the given number. In other words, if the -number is zero or positive then it is returned as-is, but if it is negative -then it is multiplied by -1 to make it positive before returning it. +``` +abs(number) +``` -## Examples +The number is the number you want the absolute value of. + +In the following example, the function returns the absolute value of 23, 0, and -12.4. ``` > abs(23) @@ -19,3 +26,17 @@ then it is multiplied by -1 to make it positive before returning it. > abs(-12.4) 12.4 ``` + +## Example use case +The following example defines a variable num that is negative. The function outputs the absolute value of num, which is 10. +``` +variable "num" { + default = -10 +} + +output "absolute_value" { + value = abs(var.num) +} +``` +## Related Functions +[signum](/terraform/language/functions/signum) determines the sign of a number, returning a number between -1 and 1 to represent the sign