The branch stable/12 has been updated by dim:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=cedb8de26ccc46a9b8215dad58f411b93d101db5

commit cedb8de26ccc46a9b8215dad58f411b93d101db5
Author:     Steve Kargl <[email protected]>
AuthorDate: 2021-02-08 19:45:30 +0000
Commit:     Dimitry Andric <[email protected]>
CommitDate: 2021-02-15 18:10:40 +0000

    Fix incorrect powf(3) result with x near 1 and |y| much larger than 1
    
    This adjusts the check to trigger overflow/underflow to a slightly lower
    value.
    
    Before: powf(9.999995e-01, -1.342177e+08) -> inf
    After:  powf(9.999995e-01, -1.342177e+08) -> 1.858724e+31
    
    (cherry picked from commit 93fc67896550548f91b307dbe3053f11db5d4a8a)
    
    Add test case for 93fc67896550 (incorrect powf(3) result)
    
    This adds the test case to contrib/netbsd-tests/lib/libm/t_pow.c, as it
    is currently the only place testing pow(3) and friends.
    
    (cherry picked from commit 51af03328755c9095e94d20858a8d10acfe412ae)
---
 contrib/netbsd-tests/lib/libm/t_pow.c | 22 ++++++++++++++++++++++
 lib/msun/src/e_powf.c                 |  2 +-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/contrib/netbsd-tests/lib/libm/t_pow.c 
b/contrib/netbsd-tests/lib/libm/t_pow.c
index 7afee9f6dffa..09e72be7311b 100644
--- a/contrib/netbsd-tests/lib/libm/t_pow.c
+++ b/contrib/netbsd-tests/lib/libm/t_pow.c
@@ -637,6 +637,27 @@ ATF_TC_BODY(powf_zero_y, tc)
        }
 }
 
+ATF_TC(powf_near_one_x_huge_y);
+ATF_TC_HEAD(powf_near_one_x_huge_y, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test powf(->1, huge) != inf");
+}
+
+ATF_TC_BODY(powf_near_one_x_huge_y, tc)
+{
+       const float x =  0x1.ffffeep-1f;   /*  9.999995e-01f */
+       const float y = -0x1.000002p+27f;  /* -1.342177e+08f */
+       const float e =  0x1.d53532p+103f; /*  1.858724e+31f */
+       const float ulp = __FLT_EPSILON__;
+       float z;
+
+       z = powf(x, y);
+
+       ATF_CHECK(isinf(z) == 0);
+       ATF_CHECK(fabsf(z - e) <= 2 * ulp);
+}
+
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -661,6 +682,7 @@ ATF_TP_ADD_TCS(tp)
        ATF_TP_ADD_TC(tp, powf_one_pos_x);
        ATF_TP_ADD_TC(tp, powf_zero_x);
        ATF_TP_ADD_TC(tp, powf_zero_y);
+       ATF_TP_ADD_TC(tp, powf_near_one_x_huge_y);
 
        return atf_no_error();
 }
diff --git a/lib/msun/src/e_powf.c b/lib/msun/src/e_powf.c
index 53f1d37d6bec..33eedad50b16 100644
--- a/lib/msun/src/e_powf.c
+++ b/lib/msun/src/e_powf.c
@@ -136,7 +136,7 @@ __ieee754_powf(float x, float y)
     /* |y| is huge */
        if(iy>0x4d000000) { /* if |y| > 2**27 */
        /* over/underflow if x is not close to one */
-           if(ix<0x3f7ffff8) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
+           if(ix<0x3f7ffff7) return (hy<0)? sn*huge*huge:sn*tiny*tiny;
            if(ix>0x3f800007) return (hy>0)? sn*huge*huge:sn*tiny*tiny;
        /* now |1-x| is tiny <= 2**-20, suffice to compute
           log(x) by x-x^2/2+x^3/3-x^4/4 */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to