From c3fe2135a494d773ad53fef3fa4793b27fef54c3 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 14 May 2020 16:58:20 +0200 Subject: [PATCH] math.fabs --- vlib/math/math.v | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vlib/math/math.v b/vlib/math/math.v index 7779b21240..aecbd12fa5 100644 --- a/vlib/math/math.v +++ b/vlib/math/math.v @@ -68,6 +68,13 @@ pub fn digits(_n, base int) []int { return res } +pub fn fabs(x f64) f64 { + if x < 0.0 { + return -x + } + return x +} + // gcd calculates greatest common (positive) divisor (or zero if a and b are both zero). pub fn gcd(a_, b_ i64) i64 { mut a := a_