diff --git a/README.md b/README.md index fc86fbb..db47e02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/include/pal_math.h b/include/pal_math.h index e1d4bcc..fa9fec6 100644 --- a/include/pal_math.h +++ b/include/pal_math.h @@ -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))) diff --git a/src/math/Makefile.am b/src/math/Makefile.am index 3dea94c..9f742ee 100644 --- a/src/math/Makefile.am +++ b/src/math/Makefile.am @@ -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 \ diff --git a/src/math/p_ceil.c b/src/math/p_ceil.c new file mode 100644 index 0000000..fbdf564 --- /dev/null +++ b/src/math/p_ceil.c @@ -0,0 +1,20 @@ +#include + +/* + * + * 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) + * + */ diff --git a/tests/math/Makefile.am b/tests/math/Makefile.am index 332b441..b8bdfec 100644 --- a/tests/math/Makefile.am +++ b/tests/math/Makefile.am @@ -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 \ @@ -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 \ @@ -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) @@ -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 @@ -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) diff --git a/tests/math/gold/p_ceil_f32.dat b/tests/math/gold/p_ceil_f32.dat new file mode 100644 index 0000000..cd01e98 --- /dev/null +++ b/tests/math/gold/p_ceil_f32.dat @@ -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 diff --git a/tests/math/p_ceil.c b/tests/math/p_ceil.c new file mode 100644 index 0000000..0878f4d --- /dev/null +++ b/tests/math/p_ceil.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] = ceilf(ai[i]); +}