commit 4b3469fb5b7fd28e9d8c53865bcd35a164d64e17
parent 260becc0e4afeef9ea5db15112a7581305537f98
Author: vaplv <vaplv@free.fr>
Date: Mon, 3 Oct 2016 16:26:29 +0200
Implement and test the sign function
Diffstat:
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/math.h b/src/math.h
@@ -74,6 +74,12 @@ signf(const float flt)
return flt < 0.f ? -1.f : 1.f;
}
+static FINLINE double
+sign(const double dbl)
+{
+ return dbl < 0.0 ? -1.0 : 1.0;
+}
+
static FINLINE char
eq_eps(const double a, const double b, const double eps)
{
diff --git a/src/test_math.c b/src/test_math.c
@@ -127,6 +127,10 @@ main(int argc, char** argv)
CHECK(signf(-3.14159f), -1.f);
CHECK(signf(1.23f), 1.f);
CHECK(signf(0.f), 1.f);
+ CHECK(sign(-3.14159), -1.0);
+ CHECK(sign(1.23), 1.0);
+ CHECK(sign(0.0), 1.0);
+
return 0;
}