diff --git a/README.md b/README.md index fc86fbb..45ebf21 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,7 @@ FUNCTION | NOTES [p_div()](src/math/p_div.c) | division [p_dot()](src/math/p_dot.c) | dot product [p_exp()](src/math/p_exp.c) | exponential +[p_floor()](src/math/p_floor.c) | floor [p_ftoi()](src/math/p_ftoi.c) | float to [p_itof()](src/math/p_itof.c) | integer to float conversion [p_inv()](src/math/p_inv.c) | inverse diff --git a/include/pal_math.h b/include/pal_math.h index e1d4bcc..e8eb531 100644 --- a/include/pal_math.h +++ b/include/pal_math.h @@ -77,6 +77,22 @@ * */ + +#define p_floor_f32( a, c, n) { \ + int i; float x; \ + for ( i = 0; i < n; i++) \ + { \ + const float *pa = (a+i); \ + float *pc = (c+i); \ + x = *pa; \ + *pc = (int)x - ((int)x > x); \ + }} + + + + + + /* Get the floor of x */ #define M_FLOOR(x) ((int)((int)x - ((int)x > x))) diff --git a/src/math/Makefile.am b/src/math/Makefile.am index 3dea94c..506d421 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_exp.h \ + p_floor.c \ p_ftoi.c \ p_inv.c \ p_invcbrt.c \ diff --git a/src/math/p_floor.c b/src/math/p_floor.c new file mode 100644 index 0000000..7502662 --- /dev/null +++ b/src/math/p_floor.c @@ -0,0 +1,20 @@ +#include + +/* + * + * Compute the floor of a + * + * @param a Pointer to input vector + * + * @param c Pointer to output vector + * + * @param n Size of 'a' and 'c' vector. + * + * @return None + * + */ +/* + * in pal_math.h file + * #define p_floor_f32( a, c, n) + * + */ \ No newline at end of file diff --git a/tests/math/Makefile.am b/tests/math/Makefile.am index 332b441..0f7c42d 100644 --- a/tests/math/Makefile.am +++ b/tests/math/Makefile.am @@ -39,6 +39,7 @@ BUILT_SOURCES = \ gold/p_div_f32.gold.h \ gold/p_dot_f32.gold.h \ gold/p_exp_f32.gold.h \ + gold/p_floor_f32.gold.h \ gold/p_invcbrt_f32.gold.h \ gold/p_inv_f32.gold.h \ gold/p_invsqrt_f32.gold.h \ @@ -97,6 +98,7 @@ check_PROGRAMS = \ check_p_div_f32 \ check_p_dot_f32 \ check_p_exp_f32 \ + check_p_floor_f32 \ check_p_ftoi \ check_p_invcbrt_f32 \ check_p_inv_f32 \ @@ -142,6 +144,7 @@ check_p_cosh_f32_SOURCES = $(SIMPLE) p_cosh.c check_p_div_f32_SOURCES = $(SIMPLE) check_p_dot_f32_SOURCES = $(SIMPLE) check_p_exp_f32_SOURCES = $(SIMPLE) p_exp.c +check_p_floor_f32_SOURCES = $(SIMPLE) p_floor.c check_p_ftoi_SOURCES = $(NOTEST) check_p_inv_f32_SOURCES = $(SIMPLE) check_p_invcbrt_f32_SOURCES = $(SIMPLE) @@ -187,6 +190,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_floor_f32_CFLAGS = -DFUNCTION=p_floor_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 @@ -234,6 +238,7 @@ check_p_cosh_f32_LDFLAGS = $(CHECKLDFLAGS) check_p_div_f32_LDFLAGS = $(CHECKLDFLAGS) check_p_dot_f32_LDFLAGS = $(CHECKLDFLAGS) check_p_exp_f32_LDFLAGS = $(CHECKLDFLAGS) +check_p_floor_f32_LDFLAGS = $(CHECKLDFLAGS) check_p_ftoi_LDFLAGS = $(CHECKLDFLAGS) check_p_invcbrt_f32_LDFLAGS = $(CHECKLDFLAGS) check_p_inv_f32_LDFLAGS = $(CHECKLDFLAGS) diff --git a/tests/math/gold/p_floor_f32.dat b/tests/math/gold/p_floor_f32.dat new file mode 100644 index 0000000..b948c99 --- /dev/null +++ b/tests/math/gold/p_floor_f32.dat @@ -0,0 +1,100 @@ +4.066949,0.000000,0.000000,4.000000 +4.963797,0.000000,0.000000,4.000000 +6.683885,0.000000,0.000000,6.000000 +10.739695,0.000000,0.000000,10.000000 +3.017981,0.000000,0.000000,3.000000 +8.858836,0.000000,0.000000,8.000000 +10.065878,0.000000,0.000000,10.000000 +2.188344,0.000000,0.000000,2.000000 +6.097290,0.000000,0.000000,6.000000 +0.461777,0.000000,0.000000,0.000000 +1.137549,0.000000,0.000000,1.000000 +2.856117,0.000000,0.000000,2.000000 +4.979738,0.000000,0.000000,4.000000 +10.290598,0.000000,0.000000,10.000000 +5.323372,0.000000,0.000000,5.000000 +9.625070,0.000000,0.000000,9.000000 +10.760364,0.000000,0.000000,10.000000 +4.402104,0.000000,0.000000,4.000000 +10.677649,0.000000,0.000000,10.000000 +2.163921,0.000000,0.000000,2.000000 +2.328892,0.000000,0.000000,2.000000 +10.046510,0.000000,0.000000,10.000000 +1.585797,0.000000,0.000000,1.000000 +9.399580,0.000000,0.000000,9.000000 +10.486999,0.000000,0.000000,10.000000 +3.513158,0.000000,0.000000,3.000000 +10.751333,0.000000,0.000000,10.000000 +8.595532,0.000000,0.000000,8.000000 +0.603052,0.000000,0.000000,0.000000 +0.205290,0.000000,0.000000,0.000000 +1.388230,0.000000,0.000000,1.000000 +4.670001,0.000000,0.000000,4.000000 +5.169087,0.000000,0.000000,5.000000 +5.588467,0.000000,0.000000,5.000000 +4.409697,0.000000,0.000000,4.000000 +8.187068,0.000000,0.000000,8.000000 +3.447303,0.000000,0.000000,3.000000 +0.991927,0.000000,0.000000,0.000000 +7.891764,0.000000,0.000000,7.000000 +7.060945,0.000000,0.000000,7.000000 +1.453704,0.000000,0.000000,1.000000 +6.545666,0.000000,0.000000,6.000000 +9.917062,0.000000,0.000000,9.000000 +6.433443,0.000000,0.000000,6.000000 +5.836264,0.000000,0.000000,5.000000 +4.240434,0.000000,0.000000,4.000000 +2.574865,0.000000,0.000000,2.000000 +5.596628,0.000000,0.000000,5.000000 +8.642539,0.000000,0.000000,8.000000 +10.768866,0.000000,0.000000,10.000000 +-5.276901,0.000000,0.000000,-6.000000 +-10.971431,0.000000,0.000000,-11.000000 +-9.815376,0.000000,0.000000,-10.000000 +-4.379051,0.000000,0.000000,-5.000000 +-6.887363,0.000000,0.000000,-7.000000 +-9.302376,0.000000,0.000000,-10.000000 +-7.892209,0.000000,0.000000,-8.000000 +-4.155048,0.000000,0.000000,-5.000000 +-4.414260,0.000000,0.000000,-5.000000 +-8.495261,0.000000,0.000000,-9.000000 +-4.360338,0.000000,0.000000,-5.000000 +-5.802490,0.000000,0.000000,-6.000000 +-10.681615,0.000000,0.000000,-11.000000 +-9.529425,0.000000,0.000000,-10.000000 +-0.390957,0.000000,0.000000,-1.000000 +-1.607664,0.000000,0.000000,-2.000000 +-4.232845,0.000000,0.000000,-5.000000 +-1.354612,0.000000,0.000000,-2.000000 +-2.599591,0.000000,0.000000,-3.000000 +-9.640962,0.000000,0.000000,-10.000000 +-8.415557,0.000000,0.000000,-9.000000 +-1.569648,0.000000,0.000000,-2.000000 +-5.186628,0.000000,0.000000,-6.000000 +-7.332620,0.000000,0.000000,-8.000000 +-5.519443,0.000000,0.000000,-6.000000 +-8.539244,0.000000,0.000000,-9.000000 +-0.573054,0.000000,0.000000,-1.000000 +-8.094308,0.000000,0.000000,-9.000000 +-0.652224,0.000000,0.000000,-1.000000 +-6.731945,0.000000,0.000000,-7.000000 +-7.863175,0.000000,0.000000,-8.000000 +-5.929125,0.000000,0.000000,-6.000000 +-4.219728,0.000000,0.000000,-5.000000 +-4.194903,0.000000,0.000000,-5.000000 +-7.824528,0.000000,0.000000,-8.000000 +-8.623443,0.000000,0.000000,-9.000000 +-0.013631,0.000000,0.000000,-1.000000 +-4.716737,0.000000,0.000000,-5.000000 +-1.778491,0.000000,0.000000,-2.000000 +-4.427891,0.000000,0.000000,-5.000000 +-10.728351,0.000000,0.000000,-11.000000 +-6.138829,0.000000,0.000000,-7.000000 +-7.746733,0.000000,0.000000,-8.000000 +-10.409966,0.000000,0.000000,-11.000000 +-2.184606,0.000000,0.000000,-3.000000 +-5.654042,0.000000,0.000000,-6.000000 +-1.017630,0.000000,0.000000,-2.000000 +-3.933804,0.000000,0.000000,-4.000000 +-7.008654,0.000000,0.000000,-8.000000 +-1.133573,0.000000,0.000000,-2.000000 diff --git a/tests/math/p_floor.c b/tests/math/p_floor.c new file mode 100644 index 0000000..7502662 --- /dev/null +++ b/tests/math/p_floor.c @@ -0,0 +1,20 @@ +#include + +/* + * + * Compute the floor of a + * + * @param a Pointer to input vector + * + * @param c Pointer to output vector + * + * @param n Size of 'a' and 'c' vector. + * + * @return None + * + */ +/* + * in pal_math.h file + * #define p_floor_f32( a, c, n) + * + */ \ No newline at end of file