Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: p_floor: Implement Floor Function #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions include/pal_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
1 change: 1 addition & 0 deletions src/math/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
20 changes: 20 additions & 0 deletions src/math/p_floor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <pal.h>

/*
*
* 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)
*
*/
5 changes: 5 additions & 0 deletions tests/math/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
100 changes: 100 additions & 0 deletions tests/math/gold/p_floor_f32.dat
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions tests/math/p_floor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <pal.h>

/*
*
* 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)
*
*/