From c1a08f02af7df574f9315577d67f9a5cf6ecb6d2 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Fri, 19 Sep 2014 11:36:33 -0400 Subject: [PATCH 1/6] Simplify code, avoid compiler warnings --- src/e_j0.c | 4 ++-- src/e_j0f.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/e_j0.c b/src/e_j0.c index aa757bb..0f8c4f9 100644 --- a/src/e_j0.c +++ b/src/e_j0.c @@ -278,7 +278,7 @@ static const double pS2[5] = { if(ix>=0x40200000) {p = pR8; q= pS8;} else if(ix>=0x40122E8B){p = pR5; q= pS5;} else if(ix>=0x4006DB6D){p = pR3; q= pS3;} - else if(ix>=0x40000000){p = pR2; q= pS2;} + else {p = pR2; q= pS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); @@ -373,7 +373,7 @@ static const double qS2[6] = { if(ix>=0x40200000) {p = qR8; q= qS8;} else if(ix>=0x40122E8B){p = qR5; q= qS5;} else if(ix>=0x4006DB6D){p = qR3; q= qS3;} - else if(ix>=0x40000000){p = qR2; q= qS2;} + else {p = qR2; q= qS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); diff --git a/src/e_j0f.c b/src/e_j0f.c index 61b59e6..9dea1a2 100644 --- a/src/e_j0f.c +++ b/src/e_j0f.c @@ -234,7 +234,7 @@ static const float pS2[5] = { if(ix>=0x41000000) {p = pR8; q= pS8;} else if(ix>=0x40f71c58){p = pR5; q= pS5;} else if(ix>=0x4036db68){p = pR3; q= pS3;} - else if(ix>=0x40000000){p = pR2; q= pS2;} + else {p = pR2; q= pS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); @@ -329,7 +329,7 @@ static const float qS2[6] = { if(ix>=0x41000000) {p = qR8; q= qS8;} else if(ix>=0x40f71c58){p = qR5; q= qS5;} else if(ix>=0x4036db68){p = qR3; q= qS3;} - else if(ix>=0x40000000){p = qR2; q= qS2;} + else {p = qR2; q= qS2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); From e2138aed2e6421bac7d65d3201541124800e0189 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Fri, 19 Sep 2014 11:48:34 -0400 Subject: [PATCH 2/6] Avoid compiler warnings --- src/e_j1.c | 4 ++-- src/e_j1f.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/e_j1.c b/src/e_j1.c index dfb8f78..628cd54 100644 --- a/src/e_j1.c +++ b/src/e_j1.c @@ -272,7 +272,7 @@ static const double ps2[5] = { if(ix>=0x40200000) {p = pr8; q= ps8;} else if(ix>=0x40122E8B){p = pr5; q= ps5;} else if(ix>=0x4006DB6D){p = pr3; q= ps3;} - else if(ix>=0x40000000){p = pr2; q= ps2;} + else {p = pr2; q= ps2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); @@ -368,7 +368,7 @@ static const double qs2[6] = { if(ix>=0x40200000) {p = qr8; q= qs8;} else if(ix>=0x40122E8B){p = qr5; q= qs5;} else if(ix>=0x4006DB6D){p = qr3; q= qs3;} - else if(ix>=0x40000000){p = qr2; q= qs2;} + else {p = qr2; q= qs2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); diff --git a/src/e_j1f.c b/src/e_j1f.c index aeba0f3..7faeffd 100644 --- a/src/e_j1f.c +++ b/src/e_j1f.c @@ -229,7 +229,7 @@ static const float ps2[5] = { if(ix>=0x41000000) {p = pr8; q= ps8;} else if(ix>=0x40f71c58){p = pr5; q= ps5;} else if(ix>=0x4036db68){p = pr3; q= ps3;} - else if(ix>=0x40000000){p = pr2; q= ps2;} + else {p = pr2; q= ps2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); @@ -325,7 +325,7 @@ static const float qs2[6] = { if(ix>=0x40200000) {p = qr8; q= qs8;} else if(ix>=0x40f71c58){p = qr5; q= qs5;} else if(ix>=0x4036db68){p = qr3; q= qs3;} - else if(ix>=0x40000000){p = qr2; q= qs2;} + else {p = qr2; q= qs2;} z = one/(x*x); r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); From ca3aaa3a824e06bad1fe9a8f4c30e066a08e2b22 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Fri, 19 Sep 2014 11:48:43 -0400 Subject: [PATCH 3/6] Remove trailing whitespace in makefile --- src/Make.files | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Make.files b/src/Make.files index 668af4c..2775cb9 100644 --- a/src/Make.files +++ b/src/Make.files @@ -35,8 +35,8 @@ $(CUR_SRCS) = common.c \ ifneq ($(OS), WINNT) $(CUR_SRCS) += s_nan.c -endif - +endif + ifneq ($(ARCH), arm) # C99 long double functions $(CUR_SRCS) += s_copysignl.c s_fabsl.c s_llrintl.c s_lrintl.c s_modfl.c From 9c8e061ab180a497d7397eef7843e3cff3cd948f Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 22 Sep 2014 16:01:47 -0400 Subject: [PATCH 4/6] Add comments describing valid argument range for internal functions --- src/e_j0.c | 2 ++ src/e_j0f.c | 2 ++ src/e_j1.c | 2 ++ src/e_j1f.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/e_j0.c b/src/e_j0.c index 0f8c4f9..f03c054 100644 --- a/src/e_j0.c +++ b/src/e_j0.c @@ -268,6 +268,7 @@ static const double pS2[5] = { 1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static double pzero(double x) { const double *p,*q; @@ -363,6 +364,7 @@ static const double qS2[6] = { -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static double qzero(double x) { const double *p,*q; diff --git a/src/e_j0f.c b/src/e_j0f.c index 9dea1a2..a621e56 100644 --- a/src/e_j0f.c +++ b/src/e_j0f.c @@ -224,6 +224,7 @@ static const float pS2[5] = { 1.4657617569e+01, /* 0x416a859a */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static float pzerof(float x) { const float *p,*q; @@ -319,6 +320,7 @@ static const float qS2[6] = { -5.3109550476e+00, /* 0xc0a9f358 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static float qzerof(float x) { const float *p,*q; diff --git a/src/e_j1.c b/src/e_j1.c index 628cd54..a1007eb 100644 --- a/src/e_j1.c +++ b/src/e_j1.c @@ -262,6 +262,7 @@ static const double ps2[5] = { 8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static double pone(double x) { const double *p,*q; @@ -358,6 +359,7 @@ static const double qs2[6] = { -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static double qone(double x) { const double *p,*q; diff --git a/src/e_j1f.c b/src/e_j1f.c index 7faeffd..ef38a01 100644 --- a/src/e_j1f.c +++ b/src/e_j1f.c @@ -219,6 +219,7 @@ static const float ps2[5] = { 8.3646392822e+00, /* 0x4105d590 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static float ponef(float x) { const float *p,*q; @@ -315,6 +316,7 @@ static const float qs2[6] = { -4.9594988823e+00, /* 0xc09eb437 */ }; + /* Note: This function is only called for ix>=0x40000000 (see above) */ static float qonef(float x) { const float *p,*q; From 2b7040952eea79f0a11bd1d3dd51326cc86520fc Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 22 Sep 2014 16:18:53 -0400 Subject: [PATCH 5/6] Add assert statements --- src/e_j0.c | 4 ++++ src/e_j0f.c | 4 ++++ src/e_j1.c | 4 ++++ src/e_j1f.c | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/e_j0.c b/src/e_j0.c index f03c054..684bd56 100644 --- a/src/e_j0.c +++ b/src/e_j0.c @@ -11,6 +11,8 @@ * ==================================================== */ +#include + #include "cdefs-compat.h" //__FBSDID("$FreeBSD: src/lib/msun/src/e_j0.c,v 1.9 2008/02/22 02:30:35 das Exp $"); @@ -276,6 +278,7 @@ static const double pS2[5] = { int32_t ix; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x40200000) {p = pR8; q= pS8;} else if(ix>=0x40122E8B){p = pR5; q= pS5;} else if(ix>=0x4006DB6D){p = pR3; q= pS3;} @@ -372,6 +375,7 @@ static const double qS2[6] = { int32_t ix; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x40200000) {p = qR8; q= qS8;} else if(ix>=0x40122E8B){p = qR5; q= qS5;} else if(ix>=0x4006DB6D){p = qR3; q= qS3;} diff --git a/src/e_j0f.c b/src/e_j0f.c index a621e56..ee32fe1 100644 --- a/src/e_j0f.c +++ b/src/e_j0f.c @@ -13,6 +13,8 @@ * ==================================================== */ +#include + #include "cdefs-compat.h" //__FBSDID("$FreeBSD: src/lib/msun/src/e_j0f.c,v 1.8 2008/02/22 02:30:35 das Exp $"); @@ -232,6 +234,7 @@ static const float pS2[5] = { int32_t ix; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x41000000) {p = pR8; q= pS8;} else if(ix>=0x40f71c58){p = pR5; q= pS5;} else if(ix>=0x4036db68){p = pR3; q= pS3;} @@ -328,6 +331,7 @@ static const float qS2[6] = { int32_t ix; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x41000000) {p = qR8; q= qS8;} else if(ix>=0x40f71c58){p = qR5; q= qS5;} else if(ix>=0x4036db68){p = qR3; q= qS3;} diff --git a/src/e_j1.c b/src/e_j1.c index a1007eb..b084dd9 100644 --- a/src/e_j1.c +++ b/src/e_j1.c @@ -11,6 +11,8 @@ * ==================================================== */ +#include + #include "cdefs-compat.h" //__FBSDID("$FreeBSD: src/lib/msun/src/e_j1.c,v 1.9 2008/02/22 02:30:35 das Exp $"); @@ -270,6 +272,7 @@ static const double ps2[5] = { int32_t ix; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x40200000) {p = pr8; q= ps8;} else if(ix>=0x40122E8B){p = pr5; q= ps5;} else if(ix>=0x4006DB6D){p = pr3; q= ps3;} @@ -367,6 +370,7 @@ static const double qs2[6] = { int32_t ix; GET_HIGH_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x40200000) {p = qr8; q= qs8;} else if(ix>=0x40122E8B){p = qr5; q= qs5;} else if(ix>=0x4006DB6D){p = qr3; q= qs3;} diff --git a/src/e_j1f.c b/src/e_j1f.c index ef38a01..c103f2e 100644 --- a/src/e_j1f.c +++ b/src/e_j1f.c @@ -13,6 +13,8 @@ * ==================================================== */ +#include + #include "cdefs-compat.h" //__FBSDID("$FreeBSD: src/lib/msun/src/e_j1f.c,v 1.8 2008/02/22 02:30:35 das Exp $"); @@ -227,6 +229,7 @@ static const float ps2[5] = { int32_t ix; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x41000000) {p = pr8; q= ps8;} else if(ix>=0x40f71c58){p = pr5; q= ps5;} else if(ix>=0x4036db68){p = pr3; q= ps3;} @@ -324,6 +327,7 @@ static const float qs2[6] = { int32_t ix; GET_FLOAT_WORD(ix,x); ix &= 0x7fffffff; + assert(ix>=0x40000000 && ix<=0x48000000); if(ix>=0x40200000) {p = qr8; q= qs8;} else if(ix>=0x40f71c58){p = qr5; q= qs5;} else if(ix>=0x4036db68){p = qr3; q= qs3;} From f5b2148a221d7bf2337ee28de0edb37e4c2a3c0d Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 22 Sep 2014 23:26:22 -0400 Subject: [PATCH 6/6] Use CFLAGS to build self-tests --- test/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Makefile b/test/Makefile index 7782924..5aae3d4 100644 --- a/test/Makefile +++ b/test/Makefile @@ -4,13 +4,13 @@ include ../Make.inc all: test-double test-float # test-double-system test-float-system test-double: test-double.c libm-test.c - $(CC) -g $@.c -D__BSD_VISIBLE -I ../include -I../src ../libopenlibm.a -o $@ + $(CC) $(CFLAGS) -g $@.c -D__BSD_VISIBLE -I ../include -I../src ../libopenlibm.a -o $@ test-float: test-float.c libm-test.c - $(CC) -g $@.c -D__BSD_VISIBLE -I ../include -I../src ../libopenlibm.a -o $@ + $(CC) $(CFLAGS) -g $@.c -D__BSD_VISIBLE -I ../include -I../src ../libopenlibm.a -o $@ test-double-system: test-double.c libm-test.c - $(CC) -g $< -DSYS_MATH_H -lm -o $@ + $(CC) $(CFLAGS) -g $< -DSYS_MATH_H -lm -o $@ test-float-system: test-float.c libm-test.c - $(CC) -g $< -DSYS_MATH_H -lm -o $@ + $(CC) $(CFLAGS) -g $< -DSYS_MATH_H -lm -o $@