From 5810608d70ad5ab51e74913d2e507a698faeb37d Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Thu, 2 Jul 2015 18:41:59 -0400 Subject: [PATCH 1/8] math:fmod: Implement the floating-point remainder value function. Add a basic implementation of the function p_fmod_f32. The function _fmod is defined as static inline in the p_fmod.h header so that other functions in that directory could use it. Signed-off-by: Mansour Moufid --- include/pal_math.h | 3 +++ src/math/Makefile.am | 1 + src/math/p_fmod.c | 20 ++++++++++++++++++++ src/math/p_fmod.h | 21 +++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/math/p_fmod.c create mode 100644 src/math/p_fmod.h diff --git a/include/pal_math.h b/include/pal_math.h index 46713b7..725d4c6 100644 --- a/include/pal_math.h +++ b/include/pal_math.h @@ -145,6 +145,9 @@ void p_div_f32(const float *a, const float *b, float *c, int n); /*exponential: c = exp ( a ) */ void p_exp_f32(const float *a, float *c, int n); +/*floating-point remainder: c = a - i * x */ +void p_fmod_f32(const float *a, float *c, int n, const float x); + /*inverse: c = 1 / ( a ) */ void p_inv_f32(const float *a, float *c, int n); diff --git a/src/math/Makefile.am b/src/math/Makefile.am index 9232fbf..7084bee 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -21,6 +21,7 @@ libpal_math_la_SOURCES = \ p_div.c \ p_dot.c \ p_exp.c \ + p_fmod.c \ p_ftoi.c \ p_inv.c \ p_invcbrt.c \ diff --git a/src/math/p_fmod.c b/src/math/p_fmod.c new file mode 100644 index 0000000..9dd5a2f --- /dev/null +++ b/src/math/p_fmod.c @@ -0,0 +1,20 @@ +#include + +#include "p_fmod.h" + +/** + * Compute the floating-point remainder value of x / y. + * + * The floating-point remainder of x / y is r = x - i * y for some i, + * such that 0 <= r <= y. + * + * @param a Pointer to the input vector + * @param c Pointer to the output vector + * @param n The size of the a and c vectors + * @param x The divisor + * @return None + */ +void p_fmod_f32(const float *a, float *c, int n, const float x) +{ + _fmod(a, c, n, x); +} diff --git a/src/math/p_fmod.h b/src/math/p_fmod.h new file mode 100644 index 0000000..cc81411 --- /dev/null +++ b/src/math/p_fmod.h @@ -0,0 +1,21 @@ +#pragma once + +/* Return the remainder of x / y. */ +static inline float __fmod(const float x, const float y) +{ + float i; + i = x / y; + return x - i * y; +} + +/* Map __fmod on a array. */ +static inline void _fmod(const float *a, float *c, int n, const float x) +{ + int i; + float tmp; + for (i = 0; i < n; i++) { + /* With temporary variable, a can overlap c. */ + tmp = __fmod(a[i], x); + c[i] = tmp; + } +} From 83725180f521fbfee9526bd509346b93e803be69 Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 13:18:38 -0400 Subject: [PATCH 2/8] math:fmod: Fix the remainder algorithm. Signed-off-by: Mansour Moufid --- src/math/p_fmod.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/p_fmod.h b/src/math/p_fmod.h index cc81411..afec06e 100644 --- a/src/math/p_fmod.h +++ b/src/math/p_fmod.h @@ -3,7 +3,7 @@ /* Return the remainder of x / y. */ static inline float __fmod(const float x, const float y) { - float i; + long int i; i = x / y; return x - i * y; } From 5ff5dd5ecffa2dc9fbf302b71b13615e1369cf12 Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 13:21:04 -0400 Subject: [PATCH 3/8] math:fmod: Add the p_fmod_2pi_f32 function. Signed-off-by: Mansour Moufid --- include/pal_math.h | 3 +++ src/math/p_fmod.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/pal_math.h b/include/pal_math.h index 725d4c6..009d45e 100644 --- a/include/pal_math.h +++ b/include/pal_math.h @@ -148,6 +148,9 @@ void p_exp_f32(const float *a, float *c, int n); /*floating-point remainder: c = a - i * x */ void p_fmod_f32(const float *a, float *c, int n, const float x); +/*floating-point remainder with divisor 2pi: c = a - i * 2pi */ +void p_fmod_2pi_f32(const float *a, float *c, int n); + /*inverse: c = 1 / ( a ) */ void p_inv_f32(const float *a, float *c, int n); diff --git a/src/math/p_fmod.c b/src/math/p_fmod.c index 9dd5a2f..4889281 100644 --- a/src/math/p_fmod.c +++ b/src/math/p_fmod.c @@ -18,3 +18,13 @@ void p_fmod_f32(const float *a, float *c, int n, const float x) { _fmod(a, c, n, x); } + +/** + * Compute the floating-point remainder with divisor 2pi. + * + * See p_fmod_f32 for details. + */ +void p_fmod_2pi_f32(const float *a, float *c, int n) +{ + _fmod(a, c, n, 2.f * M_PI); +} From 81265323578e6ce0ce27cf19aabaa8f3c443237b Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 13:22:31 -0400 Subject: [PATCH 4/8] math:fmod: Add unit tests for the p_fmod_2pi_f32 function. Signed-off-by: Mansour Moufid --- tests/math/Makefile.am | 4 ++ tests/math/gold/p_fmod_2pi_f32.dat | 100 +++++++++++++++++++++++++++++ tests/math/p_fmod_2pi.c | 10 +++ 3 files changed, 114 insertions(+) create mode 100644 tests/math/gold/p_fmod_2pi_f32.dat create mode 100644 tests/math/p_fmod_2pi.c diff --git a/tests/math/Makefile.am b/tests/math/Makefile.am index 67400c0..b313884 100644 --- a/tests/math/Makefile.am +++ b/tests/math/Makefile.am @@ -33,6 +33,7 @@ BUILT_SOURCES = \ gold/p_div_f32.gold.h \ gold/p_dot_f32.gold.h \ gold/p_exp_f32.gold.h \ + gold/p_fmod_2pi_f32.gold.h \ gold/p_invcbrt_f32.gold.h \ gold/p_inv_f32.gold.h \ gold/p_invsqrt_f32.gold.h \ @@ -86,6 +87,7 @@ check_PROGRAMS = \ check_p_div_f32 \ check_p_dot_f32 \ check_p_exp_f32 \ + check_p_fmod_2pi_f32 \ check_p_ftoi \ check_p_invcbrt_f32 \ check_p_inv_f32 \ @@ -132,6 +134,7 @@ check_p_div_f32_SOURCES = $(SIMPLE) check_p_dot_f32_SOURCES = $(SIMPLE) check_p_exp_f32_SOURCES = $(SIMPLE) p_exp.c check_p_ftoi_SOURCES = notest.c +check_p_fmod_2pi_f32_SOURCES = $(SIMPLE) p_fmod_2pi.c check_p_inv_f32_SOURCES = $(SIMPLE) check_p_invcbrt_f32_SOURCES = $(SIMPLE) check_p_invsqrt_f32_SOURCES = $(SIMPLE) p_invsqrt.c @@ -177,6 +180,7 @@ check_p_cosh_f32_CFLAGS = -DFUNCTION=p_cosh_f32 -DIS_UNARY check_p_div_f32_CFLAGS = -DFUNCTION=p_div_f32 -DIS_BINARY check_p_dot_f32_CFLAGS = -DFUNCTION=p_dot_f32 -DIS_BINARY -DSCALAR_OUTPUT check_p_exp_f32_CFLAGS = -DFUNCTION=p_exp_f32 -DIS_UNARY +check_p_fmod_2pi_f32_CFLAGS = -DFUNCTION=p_fmod_2pi_f32 -DIS_UNARY check_p_ftoi_CFLAGS = -DFUNCTION=p_ftoi check_p_invcbrt_f32_CFLAGS = -DFUNCTION=p_invcbrt_f32 -DIS_UNARY check_p_inv_f32_CFLAGS = -DFUNCTION=p_inv_f32 -DIS_UNARY diff --git a/tests/math/gold/p_fmod_2pi_f32.dat b/tests/math/gold/p_fmod_2pi_f32.dat new file mode 100644 index 0000000..66d91ea --- /dev/null +++ b/tests/math/gold/p_fmod_2pi_f32.dat @@ -0,0 +1,100 @@ +-3.078723,0.000000,0.000000,-3.078723 +-53.290353,0.000000,0.000000,-3.024871 +39.627293,0.000000,0.000000,1.928181 +47.119613,0.000000,0.000000,3.137316 +28.556613,0.000000,0.000000,3.423872 +-41.537238,0.000000,0.000000,-3.838126 +-29.276909,0.000000,0.000000,-4.144168 +70.783611,0.000000,0.000000,1.668573 +-93.804051,0.000000,0.000000,-5.839456 +-8.702016,0.000000,0.000000,-2.418831 +-96.184184,0.000000,0.000000,-1.936404 +52.616871,0.000000,0.000000,2.351388 +66.056752,0.000000,0.000000,3.224899 +-26.458480,0.000000,0.000000,-1.325739 +-5.214358,0.000000,0.000000,-5.214358 +17.786800,0.000000,0.000000,5.220430 +85.431009,0.000000,0.000000,3.749600 +20.415441,0.000000,0.000000,1.565885 +8.028657,0.000000,0.000000,1.745472 +11.964407,0.000000,0.000000,5.681222 +29.701340,0.000000,0.000000,4.568599 +4.241830,0.000000,0.000000,4.241830 +-32.796345,0.000000,0.000000,-1.380419 +-79.851152,0.000000,0.000000,-4.452928 +-44.147396,0.000000,0.000000,-0.165099 +-31.373327,0.000000,0.000000,-6.240585 +-2.368925,0.000000,0.000000,-2.368925 +-53.992605,0.000000,0.000000,-3.727123 +-75.232182,0.000000,0.000000,-6.117144 +-20.012817,0.000000,0.000000,-1.163261 +67.044040,0.000000,0.000000,4.212187 +-24.261082,0.000000,0.000000,-5.411526 +8.756495,0.000000,0.000000,2.473310 +40.990927,0.000000,0.000000,3.291815 +15.987651,0.000000,0.000000,3.421280 +-43.387843,0.000000,0.000000,-5.688731 +63.978919,0.000000,0.000000,1.147066 +-71.461548,0.000000,0.000000,-2.346509 +58.897284,0.000000,0.000000,2.348616 +59.705592,0.000000,0.000000,3.156924 +-59.006271,0.000000,0.000000,-2.457603 +78.328453,0.000000,0.000000,2.930230 +88.558015,0.000000,0.000000,0.593421 +51.249992,0.000000,0.000000,0.984510 +-74.606099,0.000000,0.000000,-5.491060 +48.694047,0.000000,0.000000,4.711749 +39.360544,0.000000,0.000000,1.661432 +9.212317,0.000000,0.000000,2.929131 +-99.188723,0.000000,0.000000,-4.940944 +-75.421850,0.000000,0.000000,-0.023626 +-18.232908,0.000000,0.000000,-5.666537 +22.217667,0.000000,0.000000,3.368111 +74.818469,0.000000,0.000000,5.703431 +69.492239,0.000000,0.000000,0.377200 +0.354763,0.000000,0.000000,0.354763 +-13.879552,0.000000,0.000000,-1.313182 +-12.289660,0.000000,0.000000,-6.006475 +92.896310,0.000000,0.000000,4.931716 +99.808242,0.000000,0.000000,5.560462 +5.230806,0.000000,0.000000,5.230806 +68.359156,0.000000,0.000000,5.527302 +95.772657,0.000000,0.000000,1.524878 +42.239190,0.000000,0.000000,4.540078 +62.816734,0.000000,0.000000,6.268066 +-24.117945,0.000000,0.000000,-5.268389 +-44.616213,0.000000,0.000000,-0.633916 +12.679658,0.000000,0.000000,0.113287 +79.606568,0.000000,0.000000,4.208344 +48.423527,0.000000,0.000000,4.441230 +16.896658,0.000000,0.000000,4.330287 +8.103842,0.000000,0.000000,1.820657 +4.988976,0.000000,0.000000,4.988976 +50.670156,0.000000,0.000000,0.404673 +-51.317196,0.000000,0.000000,-1.051714 +-18.093993,0.000000,0.000000,-5.527622 +-69.255090,0.000000,0.000000,-0.140052 +-70.729983,0.000000,0.000000,-1.614945 +99.912301,0.000000,0.000000,5.664522 +91.797519,0.000000,0.000000,3.832925 +-23.472837,0.000000,0.000000,-4.623281 +-64.796133,0.000000,0.000000,-1.964279 +-84.808832,0.000000,0.000000,-3.127423 +-68.658054,0.000000,0.000000,-5.826201 +2.624611,0.000000,0.000000,2.624611 +-33.455337,0.000000,0.000000,-2.039411 +42.638274,0.000000,0.000000,4.939162 +16.229251,0.000000,0.000000,3.662881 +-99.355526,0.000000,0.000000,-5.107746 +93.449154,0.000000,0.000000,5.484560 +-87.285977,0.000000,0.000000,-5.604568 +-54.784142,0.000000,0.000000,-4.518659 +-71.177640,0.000000,0.000000,-2.062602 +-93.603242,0.000000,0.000000,-5.638648 +23.659030,0.000000,0.000000,4.809474 +71.034232,0.000000,0.000000,1.919194 +-91.186396,0.000000,0.000000,-3.221802 +-77.920736,0.000000,0.000000,-2.522513 +-46.719146,0.000000,0.000000,-2.736849 +35.350531,0.000000,0.000000,3.934605 +-96.979736,0.000000,0.000000,-2.731956 diff --git a/tests/math/p_fmod_2pi.c b/tests/math/p_fmod_2pi.c new file mode 100644 index 0000000..af10e96 --- /dev/null +++ b/tests/math/p_fmod_2pi.c @@ -0,0 +1,10 @@ +#include +#include "simple.h" + +void generate_ref(float *out, size_t n) +{ + size_t i; + + for (i = 0; i < n; i++) + out[i] = fmodf(ai[i], 2.0 * M_PI); +} From d8c4e9ade2b1303e6ce866e2366db86dc44da4dd Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 22:47:57 -0400 Subject: [PATCH 5/8] math:fmod: Correct the fmod function for negative input. Signed-off-by: Mansour Moufid --- src/math/p_fmod.h | 2 +- tests/math/gold/p_fmod_2pi_f32.dat | 200 ++++++++++++++--------------- tests/math/p_fmod_2pi.c | 3 +- 3 files changed, 103 insertions(+), 102 deletions(-) diff --git a/src/math/p_fmod.h b/src/math/p_fmod.h index afec06e..555c870 100644 --- a/src/math/p_fmod.h +++ b/src/math/p_fmod.h @@ -5,7 +5,7 @@ static inline float __fmod(const float x, const float y) { long int i; i = x / y; - return x - i * y; + return x - i * y + (x < 0.f ? y : 0.f); } /* Map __fmod on a array. */ diff --git a/tests/math/gold/p_fmod_2pi_f32.dat b/tests/math/gold/p_fmod_2pi_f32.dat index 66d91ea..0b5cc3a 100644 --- a/tests/math/gold/p_fmod_2pi_f32.dat +++ b/tests/math/gold/p_fmod_2pi_f32.dat @@ -1,100 +1,100 @@ --3.078723,0.000000,0.000000,-3.078723 --53.290353,0.000000,0.000000,-3.024871 -39.627293,0.000000,0.000000,1.928181 -47.119613,0.000000,0.000000,3.137316 -28.556613,0.000000,0.000000,3.423872 --41.537238,0.000000,0.000000,-3.838126 --29.276909,0.000000,0.000000,-4.144168 -70.783611,0.000000,0.000000,1.668573 --93.804051,0.000000,0.000000,-5.839456 --8.702016,0.000000,0.000000,-2.418831 --96.184184,0.000000,0.000000,-1.936404 -52.616871,0.000000,0.000000,2.351388 -66.056752,0.000000,0.000000,3.224899 --26.458480,0.000000,0.000000,-1.325739 --5.214358,0.000000,0.000000,-5.214358 -17.786800,0.000000,0.000000,5.220430 -85.431009,0.000000,0.000000,3.749600 -20.415441,0.000000,0.000000,1.565885 -8.028657,0.000000,0.000000,1.745472 -11.964407,0.000000,0.000000,5.681222 -29.701340,0.000000,0.000000,4.568599 -4.241830,0.000000,0.000000,4.241830 --32.796345,0.000000,0.000000,-1.380419 --79.851152,0.000000,0.000000,-4.452928 --44.147396,0.000000,0.000000,-0.165099 --31.373327,0.000000,0.000000,-6.240585 --2.368925,0.000000,0.000000,-2.368925 --53.992605,0.000000,0.000000,-3.727123 --75.232182,0.000000,0.000000,-6.117144 --20.012817,0.000000,0.000000,-1.163261 -67.044040,0.000000,0.000000,4.212187 --24.261082,0.000000,0.000000,-5.411526 -8.756495,0.000000,0.000000,2.473310 -40.990927,0.000000,0.000000,3.291815 -15.987651,0.000000,0.000000,3.421280 --43.387843,0.000000,0.000000,-5.688731 -63.978919,0.000000,0.000000,1.147066 --71.461548,0.000000,0.000000,-2.346509 -58.897284,0.000000,0.000000,2.348616 -59.705592,0.000000,0.000000,3.156924 --59.006271,0.000000,0.000000,-2.457603 -78.328453,0.000000,0.000000,2.930230 -88.558015,0.000000,0.000000,0.593421 -51.249992,0.000000,0.000000,0.984510 --74.606099,0.000000,0.000000,-5.491060 -48.694047,0.000000,0.000000,4.711749 -39.360544,0.000000,0.000000,1.661432 -9.212317,0.000000,0.000000,2.929131 --99.188723,0.000000,0.000000,-4.940944 --75.421850,0.000000,0.000000,-0.023626 --18.232908,0.000000,0.000000,-5.666537 -22.217667,0.000000,0.000000,3.368111 -74.818469,0.000000,0.000000,5.703431 -69.492239,0.000000,0.000000,0.377200 -0.354763,0.000000,0.000000,0.354763 --13.879552,0.000000,0.000000,-1.313182 --12.289660,0.000000,0.000000,-6.006475 -92.896310,0.000000,0.000000,4.931716 -99.808242,0.000000,0.000000,5.560462 -5.230806,0.000000,0.000000,5.230806 -68.359156,0.000000,0.000000,5.527302 -95.772657,0.000000,0.000000,1.524878 -42.239190,0.000000,0.000000,4.540078 -62.816734,0.000000,0.000000,6.268066 --24.117945,0.000000,0.000000,-5.268389 --44.616213,0.000000,0.000000,-0.633916 -12.679658,0.000000,0.000000,0.113287 -79.606568,0.000000,0.000000,4.208344 -48.423527,0.000000,0.000000,4.441230 -16.896658,0.000000,0.000000,4.330287 -8.103842,0.000000,0.000000,1.820657 -4.988976,0.000000,0.000000,4.988976 -50.670156,0.000000,0.000000,0.404673 --51.317196,0.000000,0.000000,-1.051714 --18.093993,0.000000,0.000000,-5.527622 --69.255090,0.000000,0.000000,-0.140052 --70.729983,0.000000,0.000000,-1.614945 -99.912301,0.000000,0.000000,5.664522 -91.797519,0.000000,0.000000,3.832925 --23.472837,0.000000,0.000000,-4.623281 --64.796133,0.000000,0.000000,-1.964279 --84.808832,0.000000,0.000000,-3.127423 --68.658054,0.000000,0.000000,-5.826201 -2.624611,0.000000,0.000000,2.624611 --33.455337,0.000000,0.000000,-2.039411 -42.638274,0.000000,0.000000,4.939162 -16.229251,0.000000,0.000000,3.662881 --99.355526,0.000000,0.000000,-5.107746 -93.449154,0.000000,0.000000,5.484560 --87.285977,0.000000,0.000000,-5.604568 --54.784142,0.000000,0.000000,-4.518659 --71.177640,0.000000,0.000000,-2.062602 --93.603242,0.000000,0.000000,-5.638648 -23.659030,0.000000,0.000000,4.809474 -71.034232,0.000000,0.000000,1.919194 --91.186396,0.000000,0.000000,-3.221802 --77.920736,0.000000,0.000000,-2.522513 --46.719146,0.000000,0.000000,-2.736849 -35.350531,0.000000,0.000000,3.934605 --96.979736,0.000000,0.000000,-2.731956 +-73.151069,0.000000,0.000000,2.247155 +-41.229381,0.000000,0.000000,2.752916 +-41.571556,0.000000,0.000000,2.410741 +87.935243,0.000000,0.000000,6.253834 +72.091828,0.000000,0.000000,2.976790 +38.719546,0.000000,0.000000,1.020434 +73.946113,0.000000,0.000000,4.831074 +-56.302218,0.000000,0.000000,0.246449 +-86.870868,0.000000,0.000000,1.093726 +-62.092752,0.000000,0.000000,0.739101 +92.185153,0.000000,0.000000,4.220559 +87.685583,0.000000,0.000000,6.004174 +-73.134079,0.000000,0.000000,2.264145 +58.260211,0.000000,0.000000,1.711543 +93.208450,0.000000,0.000000,5.243856 +-57.352012,0.000000,0.000000,5.479841 +95.949440,0.000000,0.000000,1.701660 +25.358186,0.000000,0.000000,0.225445 +-73.722375,0.000000,0.000000,1.675848 +-34.751585,0.000000,0.000000,2.947527 +22.526080,0.000000,0.000000,3.676524 +96.421245,0.000000,0.000000,2.173466 +-35.379634,0.000000,0.000000,2.319477 +32.640696,0.000000,0.000000,1.224770 +70.247906,0.000000,0.000000,1.132868 +69.145630,0.000000,0.000000,0.030591 +93.967350,0.000000,0.000000,6.002756 +-32.006928,0.000000,0.000000,5.692184 +5.391561,0.000000,0.000000,5.391561 +-99.097048,0.000000,0.000000,1.433917 +67.876876,0.000000,0.000000,5.045022 +65.030388,0.000000,0.000000,2.198534 +60.885730,0.000000,0.000000,4.337062 +89.882442,0.000000,0.000000,1.917848 +-78.777811,0.000000,0.000000,2.903598 +77.015560,0.000000,0.000000,1.617336 +47.657817,0.000000,0.000000,3.675519 +-0.539278,0.000000,0.000000,5.743908 +63.199742,0.000000,0.000000,0.367888 +58.966444,0.000000,0.000000,2.417776 +27.721960,0.000000,0.000000,2.589218 +26.160962,0.000000,0.000000,1.028221 +16.848931,0.000000,0.000000,4.282561 +11.398246,0.000000,0.000000,5.115060 +-5.287673,0.000000,0.000000,0.995512 +-75.662695,0.000000,0.000000,6.018714 +17.304752,0.000000,0.000000,4.738382 +-75.666061,0.000000,0.000000,6.015348 +-30.177494,0.000000,0.000000,1.238433 +-0.402864,0.000000,0.000000,5.880321 +-50.843464,0.000000,0.000000,5.705203 +-62.476272,0.000000,0.000000,0.355581 +17.254263,0.000000,0.000000,4.687892 +-76.803239,0.000000,0.000000,4.878170 +14.964506,0.000000,0.000000,2.398135 +97.402893,0.000000,0.000000,3.155113 +-5.402715,0.000000,0.000000,0.880470 +-60.431126,0.000000,0.000000,2.400727 +70.271604,0.000000,0.000000,1.156566 +15.487283,0.000000,0.000000,2.920912 +-68.864562,0.000000,0.000000,0.250477 +18.015849,0.000000,0.000000,5.449479 +-41.245544,0.000000,0.000000,2.736754 +-73.827542,0.000000,0.000000,1.570682 +64.470133,0.000000,0.000000,1.638280 +86.252020,0.000000,0.000000,4.570611 +32.344140,0.000000,0.000000,0.928214 +95.303687,0.000000,0.000000,1.055908 +75.493892,0.000000,0.000000,0.095668 +-94.643699,0.000000,0.000000,5.887266 +-50.186897,0.000000,0.000000,0.078585 +6.115036,0.000000,0.000000,6.115036 +-34.549710,0.000000,0.000000,3.149402 +61.429573,0.000000,0.000000,4.880905 +-57.952601,0.000000,0.000000,4.879252 +-99.119640,0.000000,0.000000,1.411325 +71.558474,0.000000,0.000000,2.443436 +-50.398997,0.000000,0.000000,6.149671 +93.969644,0.000000,0.000000,6.005049 +-47.958961,0.000000,0.000000,2.306522 +82.580425,0.000000,0.000000,0.899016 +-7.909680,0.000000,0.000000,4.656691 +77.170744,0.000000,0.000000,1.772520 +94.990176,0.000000,0.000000,0.742396 +-85.007026,0.000000,0.000000,2.957568 +0.992721,0.000000,0.000000,0.992721 +-79.334674,0.000000,0.000000,2.346735 +51.929450,0.000000,0.000000,1.663967 +68.659900,0.000000,0.000000,5.828047 +-81.847852,0.000000,0.000000,6.116743 +94.112480,0.000000,0.000000,6.147886 +-81.408641,0.000000,0.000000,0.272768 +0.593477,0.000000,0.000000,0.593477 +-6.568346,0.000000,0.000000,5.998025 +17.752890,0.000000,0.000000,5.186519 +43.540731,0.000000,0.000000,5.841619 +-84.813309,0.000000,0.000000,3.151286 +-44.040582,0.000000,0.000000,6.224900 +-39.592007,0.000000,0.000000,4.390290 +-63.546451,0.000000,0.000000,5.568587 diff --git a/tests/math/p_fmod_2pi.c b/tests/math/p_fmod_2pi.c index af10e96..98719da 100644 --- a/tests/math/p_fmod_2pi.c +++ b/tests/math/p_fmod_2pi.c @@ -4,7 +4,8 @@ void generate_ref(float *out, size_t n) { size_t i; + float twopi = 2.0 * M_PI; for (i = 0; i < n; i++) - out[i] = fmodf(ai[i], 2.0 * M_PI); + out[i] = fmodf(ai[i], twopi) + (ai[i] >= 0.f ? 0.f : twopi); } From 4dba9fa370b52bece36a5e67a491739956a8b497 Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 22:49:31 -0400 Subject: [PATCH 6/8] math:fmod: Clarify the documentation of the fmod function. Use unambiguous variable names. Signed-off-by: Mansour Moufid --- src/math/p_fmod.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/math/p_fmod.c b/src/math/p_fmod.c index 4889281..9f1dcef 100644 --- a/src/math/p_fmod.c +++ b/src/math/p_fmod.c @@ -3,10 +3,11 @@ #include "p_fmod.h" /** - * Compute the floating-point remainder value of x / y. + * Compute the floating-point remainder value of a[i] / x. * - * The floating-point remainder of x / y is r = x - i * y for some i, - * such that 0 <= r <= y. + * The floating-point remainder of a[i] / x is r = a[i] - j * x + * for some integer j, for a[i] >= 0, and r = a[i] - j * x + x + * for a[i] < 0, such that 0 <= r <= x. * * @param a Pointer to the input vector * @param c Pointer to the output vector From 9c003b75a957460a91fc6fa1ecd9dc74975397dd Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 23:14:48 -0400 Subject: [PATCH 7/8] math:fmod: Rename functions which conflict with GNU headers. Signed-off-by: Mansour Moufid --- src/math/p_fmod.c | 4 ++-- src/math/p_fmod.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/math/p_fmod.c b/src/math/p_fmod.c index 9f1dcef..84f065c 100644 --- a/src/math/p_fmod.c +++ b/src/math/p_fmod.c @@ -17,7 +17,7 @@ */ void p_fmod_f32(const float *a, float *c, int n, const float x) { - _fmod(a, c, n, x); + _p_fmod(a, c, n, x); } /** @@ -27,5 +27,5 @@ void p_fmod_f32(const float *a, float *c, int n, const float x) */ void p_fmod_2pi_f32(const float *a, float *c, int n) { - _fmod(a, c, n, 2.f * M_PI); + _p_fmod(a, c, n, 2.f * M_PI); } diff --git a/src/math/p_fmod.h b/src/math/p_fmod.h index 555c870..80c61dc 100644 --- a/src/math/p_fmod.h +++ b/src/math/p_fmod.h @@ -1,7 +1,7 @@ #pragma once /* Return the remainder of x / y. */ -static inline float __fmod(const float x, const float y) +static inline float __p_fmod(const float x, const float y) { long int i; i = x / y; @@ -9,13 +9,13 @@ static inline float __fmod(const float x, const float y) } /* Map __fmod on a array. */ -static inline void _fmod(const float *a, float *c, int n, const float x) +static inline void _p_fmod(const float *a, float *c, int n, const float x) { int i; float tmp; for (i = 0; i < n; i++) { /* With temporary variable, a can overlap c. */ - tmp = __fmod(a[i], x); + tmp = __p_fmod(a[i], x); c[i] = tmp; } } From f5298c4feb67e76ba84736c0ca3ba17ea1d8c7f3 Mon Sep 17 00:00:00 2001 From: Mansour Moufid Date: Sat, 4 Jul 2015 23:37:03 -0400 Subject: [PATCH 8/8] math:fmod: Automake forgot p_fmod.h... Signed-off-by: Mansour Moufid --- src/math/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/Makefile.am b/src/math/Makefile.am index 7084bee..a07dbf7 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -21,7 +21,7 @@ libpal_math_la_SOURCES = \ p_div.c \ p_dot.c \ p_exp.c \ - p_fmod.c \ + p_fmod.c p_fmod.h \ p_ftoi.c \ p_inv.c \ p_invcbrt.c \