mbox

[1/6] util: new function abs

Message ID 1497003452-10190-1-git-send-email-jonatan.schlag@ipfire.org
State Accepted
Commit a24cff8f147eafca919f5110936d33cd5e509143
Headers

Message

Jonatan Schlag June 9, 2017, 8:17 p.m. UTC
  This function return the absolute value of a given number.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/functions/functions.util | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Michael Tremer June 15, 2017, 7:22 a.m. UTC | #1
Merged. :)

On Fri, 2017-06-09 at 12:17 +0200, Jonatan Schlag wrote:
> This function return the absolute value of a given number.
> 
> Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
> ---
>  src/functions/functions.util | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/functions/functions.util
> b/src/functions/functions.util
> index 4b6f956..699026d 100644
> --- a/src/functions/functions.util
> +++ b/src/functions/functions.util
> @@ -268,6 +268,16 @@ uuid() {
>  	echo $(</proc/sys/kernel/random/uuid)
>  }
>  
> +abs() {
> +	local val=${1}
> +
> +	if [ ${val} -lt 0 ]; then
> +		(( val *= -1 ))
> +	fi
> +
> +	echo ${val}
> +}
> +
>  rand() {
>  	local uuid="$(uuid)"
>  	echo "${uuid//-/}"