commit 2079f1d51595b798024910301b23d5043d6242f8
parent 53e79630e5f6774c81d9a5dc9fbbd601c3f11144
Author: vaplv <vaplv@free.fr>
Date: Fri, 21 Oct 2016 14:13:24 +0200
Add and test the sin_cos function
Diffstat:
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -45,6 +45,7 @@ set(RSYS_FILES_SRC
image.c
library.c
logger.c
+ math.c
mem_allocator.c
quaternion.c
str.c)
@@ -188,7 +189,7 @@ if(NOT NO_TEST)
new_test(test_list rsys)
new_test(test_logger rsys)
new_test(test_mem_allocator rsys)
- new_test(test_math ${MATH_LIB})
+ new_test(test_math ${MATH_LIB} rsys)
new_test(test_quaternion rsys)
new_test(test_ref)
new_test(test_signal rsys)
diff --git a/src/math.c b/src/math.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2013-2016 Vincent Forest (vaplv@free.fr)
+ *
+ * The RSys library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * The RSys library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
+
+#define _GNU_SOURCE
+#include "math.h"
+
+void
+sin_cos(const double d, double* s, double* c)
+{
+ ASSERT(s && c);
+#ifdef COMPILER_GCC
+ sincos(d, s, c);
+#else
+ *s = sin(d);
+ *c = cos(d);
+#endif
+}
+
diff --git a/src/math.h b/src/math.h
@@ -104,4 +104,7 @@ cos2sin(const double d)
return sin2cos(d);
}
+RSYS_API void
+sin_cos(const double d, double* s, double* c);
+
#endif /* MATH_H */
diff --git a/src/test_math.c b/src/test_math.c
@@ -24,6 +24,7 @@ int
main(int argc, char** argv)
{
double d;
+ double sinus, cosine;
float f, g;
int i;
(void)argc, (void)argv;
@@ -122,6 +123,10 @@ main(int argc, char** argv)
CHECK(eq_eps(s, tmp, 1.0e-8) || eq_eps(s, -tmp, 1.0e-8), 1);
tmp = sin2cos(s);
CHECK(eq_eps(c, tmp, 1.0e-8) || eq_eps(c, -tmp, 1.0e-8), 1);
+
+ sin_cos(d, &sinus, &cosine);
+ CHECK(eq_eps(sinus, s, 1.e-8), 1);
+ CHECK(eq_eps(cosine, c, 1.e-8), 1);
}
CHECK(signf(-3.14159f), -1.f);