Skip to content

Commit f95a6c8

Browse files
shibatchNaoki Shibata
and
Naoki Shibata
authored
This patch fixes two problems (#592)
This patch fixes the following two problems: * On aarch32, cbrt(4) was returned instead of M_PI/2 when +-INFINITY is given to atanf. * Due to a bug in gcc-13, sign of tanf(+-0) was wrong on PUREC_SCALAR and VXE. This patch also adds testing for the first problem. The second problem is detected by the existing tester. --------- Co-authored-by: Naoki Shibata <[email protected]>
1 parent bbdf0e2 commit f95a6c8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/libm-tester/tester.c

+2
Original file line numberDiff line numberDiff line change
@@ -4825,6 +4825,8 @@ void do_test() {
48254825
fprintf(stderr, "atanf : ");
48264826
for(d = -10;d < 10 && success;d += 0.002) checkAccuracy_f(mpfr_atan, child_atanf, d, 3.5);
48274827
for(d = -10000;d < 10000 && success;d += 2.1) checkAccuracy_f(mpfr_atan, child_atanf, d, 3.5);
4828+
checkAccuracy_f(mpfr_atan, child_atanf, +INFINITY, 3.5);
4829+
checkAccuracy_f(mpfr_atan, child_atanf, -INFINITY, 3.5);
48284830
showResult(success);
48294831

48304832
//

src/libm/sleefsimdsp.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ EXPORT CONST VECTOR_CC vfloat xtanf(vfloat d) {
853853
if (LIKELY(vtestallones_i_vo32(vlt_vo_vf_vf(vabs_vf_vf(d), vcast_vf_f(TRIGRANGEMAX2f*0.5f))))) {
854854
q = vrint_vi2_vf(vmul_vf_vf_vf(d, vcast_vf_f((float)(2 * M_1_PI))));
855855
u = vcast_vf_vi2(q);
856+
#if (defined(ENABLE_PUREC_SCALAR) || defined(ENABLE_PURECFMA_SCALAR) || defined(ENABLE_VXE) || defined(ENABLE_VXENOFMA) || defined(ENABLE_VXE2) || defined(ENABLE_VXE2NOFMA)) && !defined(__clang__) && __GNUC__ == 13
857+
u = vsel_vf_vo_vf_vf(veq_vo_vi2_vi2(q, vcast_vi2_i(0)), vcast_vf_f(0), u);
858+
#endif
856859
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_A2f*0.5f), x);
857860
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_B2f*0.5f), x);
858861
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_C2f*0.5f), x);
@@ -908,6 +911,9 @@ EXPORT CONST VECTOR_CC vfloat xtanf(vfloat d) {
908911

909912
q = vrint_vi2_vf(vmul_vf_vf_vf(d, vcast_vf_f((float)(2 * M_1_PI))));
910913
u = vcast_vf_vi2(q);
914+
#if (defined(ENABLE_PUREC_SCALAR) || defined(ENABLE_PURECFMA_SCALAR) || defined(ENABLE_VXE) || defined(ENABLE_VXENOFMA) || defined(ENABLE_VXE2) || defined(ENABLE_VXE2NOFMA)) && !defined(__clang__) && __GNUC__ == 13
915+
u = vsel_vf_vo_vf_vf(veq_vo_vi2_vi2(q, vcast_vi2_i(0)), vcast_vf_f(0), u);
916+
#endif
911917
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_A2f*0.5f), d);
912918
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_B2f*0.5f), x);
913919
x = vmla_vf_vf_vf_vf(u, vcast_vf_f(-PI_C2f*0.5f), x);
@@ -1770,7 +1776,7 @@ EXPORT CONST VECTOR_CC vfloat xatanf(vfloat d) {
17701776
t = vreinterpret_vf_vm(vxor_vm_vm_vm(vand_vm_vo32_vm(veq_vo_vi2_vi2(vand_vi2_vi2_vi2(q, vcast_vi2_i(2)), vcast_vi2_i(2)), vreinterpret_vm_vf(vcast_vf_f(-0.0f))), vreinterpret_vm_vf(t)));
17711777

17721778
#if defined(ENABLE_NEON32) || defined(ENABLE_NEON32VFPV4)
1773-
t = vsel_vf_vo_vf_vf(visinf_vo_vf(d), vmulsign_vf_vf_vf(vcast_vf_f(1.5874010519681994747517056f), d), t);
1779+
t = vsel_vf_vo_vf_vf(visinf_vo_vf(d), vmulsign_vf_vf_vf(vcast_vf_f(1.570796326794896557998982), d), t);
17741780
#endif
17751781

17761782
return t;

0 commit comments

Comments
 (0)