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_ceil: Implement Ceil Function #211

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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ FUNCTION | NOTES
[p_acosh()](src/math/p_acosh.c) | arc hyperbolic cosine
[p_asin()](src/math/p_asin.c) | arc sine
[p_asinh()](src/math/p_asinh.c) | arc hyperbolic sine
[p_cbrt()](src/math/p_cbrt.c) | cubic root
[p_cbrt()](src/math/p_cbrt.c) | cubic root
[p_ceil()](src/math/p_ceil.c) | ceiling
[p_cos()](src/math/p_cos.c) | cosine
[p_cosh()](src/math/p_cosh.c) | hyperbolic cosine
[p_div()](src/math/p_div.c) | division
Expand Down
15 changes: 15 additions & 0 deletions include/pal_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@
*
*/

#define p_ceil_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 @@ -16,6 +16,7 @@ libpal_math_la_SOURCES = \
p_atan.c \
p_atanh.c \
p_cbrt.c \
p_ceil.c \
p_cos.c \
p_cosh.c \
p_div.c \
Expand Down
20 changes: 20 additions & 0 deletions src/math/p_ceil.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <pal.h>

/*
*
* Compute the ceiling 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_ceil_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 @@ -34,6 +34,7 @@ BUILT_SOURCES = \
gold/p_atan_f32.gold.h \
gold/p_atanh_f32.gold.h \
gold/p_cbrt_f32.gold.h \
gold/p_ceil_f32.gold.h \
gold/p_cos_f32.gold.h \
gold/p_cosh_f32.gold.h \
gold/p_div_f32.gold.h \
Expand Down Expand Up @@ -92,6 +93,7 @@ check_PROGRAMS = \
check_p_atan_f32 \
check_p_atanh_f32 \
check_p_cbrt_f32 \
check_p_ceil_f32 \
check_p_cos_f32 \
check_p_cosh_f32 \
check_p_div_f32 \
Expand Down Expand Up @@ -137,6 +139,7 @@ check_p_atan2_f32_SOURCES = $(SIMPLE) p_atan2.c
check_p_atan_f32_SOURCES = $(SIMPLE) p_atan.c
check_p_atanh_f32_SOURCES = $(SIMPLE) p_atanh.c
check_p_cbrt_f32_SOURCES = $(SIMPLE) p_cbrt.c
check_p_ceil_f32_SOURCES = $(SIMPLE) p_ceil.c
check_p_cos_f32_SOURCES = $(SIMPLE) p_cos.c
check_p_cosh_f32_SOURCES = $(SIMPLE) p_cosh.c
check_p_div_f32_SOURCES = $(SIMPLE)
Expand Down Expand Up @@ -182,6 +185,7 @@ check_p_atan2_f32_CFLAGS = -DFUNCTION=p_atan2_f32 -DIS_BINARY
check_p_atan_f32_CFLAGS = -DFUNCTION=p_atan_f32 -DIS_UNARY
check_p_atanh_f32_CFLAGS = -DFUNCTION=p_atanh_f32 -DIS_UNARY
check_p_cbrt_f32_CFLAGS = -DFUNCTION=p_cbrt_f32 -DIS_UNARY
check_p_ceil_f32_CFLAGS = -DFUNCTION=p_ceil_f32 -DIS_UNARY
check_p_cos_f32_CFLAGS = -DFUNCTION=p_cos_f32 -DIS_UNARY
check_p_cosh_f32_CFLAGS = -DFUNCTION=p_cosh_f32 -DIS_UNARY
check_p_div_f32_CFLAGS = -DFUNCTION=p_div_f32 -DIS_BINARY
Expand Down Expand Up @@ -229,6 +233,7 @@ check_p_atan2_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_atan_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_atanh_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_cbrt_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_ceil_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_cos_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_cosh_f32_LDFLAGS = $(CHECKLDFLAGS)
check_p_div_f32_LDFLAGS = $(CHECKLDFLAGS)
Expand Down
100 changes: 100 additions & 0 deletions tests/math/gold/p_ceil_f32.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
0.872989,0.000000,0.000000,1.000000
8.655462,0.000000,0.000000,9.000000
7.485358,0.000000,0.000000,8.000000
9.373897,0.000000,0.000000,10.000000
3.526271,0.000000,0.000000,4.000000
1.496578,0.000000,0.000000,2.000000
3.417001,0.000000,0.000000,4.000000
7.990323,0.000000,0.000000,8.000000
8.364930,0.000000,0.000000,9.000000
3.634889,0.000000,0.000000,4.000000
4.136441,0.000000,0.000000,5.000000
1.956305,0.000000,0.000000,2.000000
0.132938,0.000000,0.000000,1.000000
9.142584,0.000000,0.000000,10.000000
4.381933,0.000000,0.000000,5.000000
8.757131,0.000000,0.000000,9.000000
7.482705,0.000000,0.000000,8.000000
0.931842,0.000000,0.000000,1.000000
9.740881,0.000000,0.000000,10.000000
4.203008,0.000000,0.000000,5.000000
5.093561,0.000000,0.000000,6.000000
3.853018,0.000000,0.000000,4.000000
1.881879,0.000000,0.000000,2.000000
1.355996,0.000000,0.000000,2.000000
8.732939,0.000000,0.000000,9.000000
10.900931,0.000000,0.000000,11.000000
4.056200,0.000000,0.000000,5.000000
0.981850,0.000000,0.000000,1.000000
5.191472,0.000000,0.000000,6.000000
9.759656,0.000000,0.000000,10.000000
0.252932,0.000000,0.000000,1.000000
6.064461,0.000000,0.000000,7.000000
4.931470,0.000000,0.000000,5.000000
5.254642,0.000000,0.000000,6.000000
1.954710,0.000000,0.000000,2.000000
5.974093,0.000000,0.000000,6.000000
4.267572,0.000000,0.000000,5.000000
5.371711,0.000000,0.000000,6.000000
2.964416,0.000000,0.000000,3.000000
1.632502,0.000000,0.000000,2.000000
9.006600,0.000000,0.000000,10.000000
4.617209,0.000000,0.000000,5.000000
1.105159,0.000000,0.000000,2.000000
9.139538,0.000000,0.000000,10.000000
2.759794,0.000000,0.000000,3.000000
5.487093,0.000000,0.000000,6.000000
4.413022,0.000000,0.000000,5.000000
7.758851,0.000000,0.000000,8.000000
3.935287,0.000000,0.000000,4.000000
0.670255,0.000000,0.000000,1.000000
-9.478212,0.000000,0.000000,-9.000000
-6.545200,0.000000,0.000000,-6.000000
-4.523273,0.000000,0.000000,-4.000000
-0.360091,0.000000,0.000000,-0.000000
-7.901197,0.000000,0.000000,-7.000000
-10.772564,0.000000,0.000000,-10.000000
-0.261022,0.000000,0.000000,-0.000000
-9.473749,0.000000,0.000000,-9.000000
-0.754415,0.000000,0.000000,-0.000000
-2.968846,0.000000,0.000000,-2.000000
-8.233405,0.000000,0.000000,-8.000000
-9.523699,0.000000,0.000000,-9.000000
-9.033307,0.000000,0.000000,-9.000000
-10.681227,0.000000,0.000000,-10.000000
-3.778342,0.000000,0.000000,-3.000000
-10.988017,0.000000,0.000000,-10.000000
-5.655320,0.000000,0.000000,-5.000000
-5.562266,0.000000,0.000000,-5.000000
-5.359728,0.000000,0.000000,-5.000000
-6.136088,0.000000,0.000000,-6.000000
-4.711121,0.000000,0.000000,-4.000000
-0.882681,0.000000,0.000000,-0.000000
-10.753297,0.000000,0.000000,-10.000000
-3.332632,0.000000,0.000000,-3.000000
-10.022219,0.000000,0.000000,-10.000000
-0.029443,0.000000,0.000000,-0.000000
-6.336077,0.000000,0.000000,-6.000000
-0.951593,0.000000,0.000000,-0.000000
-7.788295,0.000000,0.000000,-7.000000
-10.271365,0.000000,0.000000,-10.000000
-1.621848,0.000000,0.000000,-1.000000
-6.266507,0.000000,0.000000,-6.000000
-3.332917,0.000000,0.000000,-3.000000
-3.661474,0.000000,0.000000,-3.000000
-4.142950,0.000000,0.000000,-4.000000
-8.750466,0.000000,0.000000,-8.000000
-3.434038,0.000000,0.000000,-3.000000
-4.403973,0.000000,0.000000,-4.000000
-7.224215,0.000000,0.000000,-7.000000
-1.704805,0.000000,0.000000,-1.000000
-7.372819,0.000000,0.000000,-7.000000
-1.973972,0.000000,0.000000,-1.000000
-0.228505,0.000000,0.000000,-0.000000
-2.922479,0.000000,0.000000,-2.000000
-1.655199,0.000000,0.000000,-1.000000
-1.523199,0.000000,0.000000,-1.000000
-0.426848,0.000000,0.000000,-0.000000
-7.310519,0.000000,0.000000,-7.000000
-4.601817,0.000000,0.000000,-4.000000
-3.302929,0.000000,0.000000,-3.000000
10 changes: 10 additions & 0 deletions tests/math/p_ceil.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <math.h>
#include "simple.h"

void generate_ref(float *out, size_t n)
{
size_t i;

for (i = 0; i < n; i++)
out[i] = ceilf(ai[i]);
}