Skip to content

Commit

Permalink
small fix to atan2pi when underflow occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
PingTakPeterTang committed Jan 24, 2024
1 parent 382dbb4 commit c51869d
Show file tree
Hide file tree
Showing 23 changed files with 303 additions and 127 deletions.
8 changes: 4 additions & 4 deletions include/rvvlm.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ union sui64_fp64 {
// FP64 exp function configuration
#define RVVLM_EXPD_VSET_CONFIG "rvvlm_fp64m4.h"
#define RVVLM_EXPD_STD rvvlm_expD_std
#define RVVLM_EXPD_STD_R_EXTRA rvvlm_exp
#define RVVLM_EXPD_STD_EPSIM rvvlm_expD_std_epsim
#define RVVLM_EXPD_STD_R_EXTRA rvvlm_expD_std_r_extra
#define RVVLM_EXPD_STD_EPSIM rvvlm_exp
#define RVVLM_EXPD_TBL64 rvvlm_expD_tbl64

#define RVVLM_EXPDI_VSET_CONFIG "rvvlm_fp64m4.h"
Expand All @@ -259,8 +259,8 @@ union sui64_fp64 {
// FP64 exp2 function configuration
#define RVVLM_EXP2D_VSET_CONFIG "rvvlm_fp64m2.h"
#define RVVLM_EXP2D_STD rvvlm_exp2D_std
#define RVVLM_EXP2D_STD_R_EXTRA rvvlm_exp2
#define RVVLM_EXP2D_STD_EPSIM rvvlm_exp2D_std_epsim
#define RVVLM_EXP2D_STD_R_EXTRA rvvlm_exp2D_std_r_extra
#define RVVLM_EXP2D_STD_EPSIM rvvlm_exp2
#define RVVLM_EXP2D_TBL64 rvvlm_exp2D_tbl64

#define RVVLM_EXP2DI_VSET_CONFIG "rvvlm_fp64m2.h"
Expand Down
5 changes: 3 additions & 2 deletions include/rvvlm_atan2D.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ void F_VER1(API) {
r = __riscv_vfnmsac(divide, r, R, tmp3, vlen);
r = __riscv_vfmul(divide, r, R, vlen);
// R + r is 1/(pi * scaled_x) to extra precision
// now compute vy * (R + r)
tmp1 = __riscv_vfmul(divide, vy, 0x1.0p-55, vlen);
// now compute (2^55 vy) * (R + r)
tmp1 = __riscv_vfmul(divide, vy, 0x1.0p55, vlen);
tmp2 = __riscv_vfmul(divide, tmp1, r, vlen);
tmp1 = __riscv_vfmadd(divide, tmp1, R, tmp2, vlen);
tmp1 = __riscv_vfmul(divide, tmp1, 0x1.0p-110, vlen);
tmp1 = __riscv_vfmerge(tmp1, 0x1.0p-60, no_divide, vlen);
tmp1 = __riscv_vfsgnj(tmp1, vx, vlen);

Expand Down
6 changes: 3 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ set(TEST_SOURCES
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atanpiI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atan2.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atan2I.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atan2pi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/test_atan2pi.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atan2piI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_acosh.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_acoshI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_asinh.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_asinhI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atanh.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_atanhI.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/test_cbrt.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/test_cbrtI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_cbrt.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_cbrtI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_exp.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_expI.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/src/test_exp2.cpp
Expand Down
2 changes: 1 addition & 1 deletion test/src/test_acosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main() {

x_start = 0x1.0p0;
x_end = 0x1.0p2;
nb_tests = 400000;
nb_tests = 4000000;
report_err_fp64(rvvlm_acosh, acoshl, x_start, x_end, nb_tests);

x_start = 0x1.0p490;
Expand Down
8 changes: 4 additions & 4 deletions test/src/test_asinh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ int main() {

x_start = 0x1.0p-6;
x_end = 0x1.0p0;
nb_tests = 400000;
nb_tests = 4000000;
report_err_fp64(rvvlm_asinh, asinhl, x_start, x_end, nb_tests);

x_start = 0x1.0p0;
x_end = 0x1.0p2;
nb_tests = 400000;
nb_tests = 4000000;
report_err_fp64(rvvlm_asinh, asinhl, x_start, x_end, nb_tests);

x_start = -0x1.0p0;
Expand All @@ -51,12 +51,12 @@ int main() {

x_start = 0x1.0p490;
x_end = 0x1.0p520;
nb_tests = 4000;
nb_tests = 400000;
report_err_fp64(rvvlm_asinh, asinhl, x_start, x_end, nb_tests);

x_start = 0x1.0p1020;
x_end = 0x1.FFFFFFFFFFp1023;
nb_tests = 4000;
nb_tests = 40000;
report_err_fp64(rvvlm_asinh, asinhl, x_start, x_end, nb_tests);

return 0;
Expand Down
132 changes: 108 additions & 24 deletions test/src/test_atan2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,123 @@ int main() {
// show_special2_fp64(rvvlm_atan2, swap_xy, "Special Value handling of this
// function");

x_start = 0.5;
x_end = 2.0;
nb_x = 10;
y_start = 0x1.0p-20;
y_end = 0x1.0p-15;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p0;
y_end = 0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = 0.5;
x_end = 2.0;
nb_x = 10;
y_start = 0x1.0p-5;
y_end = 0x1.0p5;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p1020;
y_end = 0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -2.0;
x_end = -0.5;
nb_x = 10;
y_start = 0x1.0p-5;
y_end = 0x1.0p5;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p-1020;
y_end = 0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -10.0;
x_end = -10.0;
nb_x = 10;
y_start = -1.0e3;
y_end = 1.0e3;
nb_y = 400000;
x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p0;
y_end = 0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p1020;
y_end = 0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = 0x1.01p-1020;
y_end = 0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p0;
y_end = -0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p1020;
y_end = -0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p-1020;
y_end = -0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p0;
y_end = -0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p1020;
y_end = -0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
;
nb_x = 8;
y_start = -0x1.01p-1020;
y_end = -0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2, atan2l, x_start, x_end, nb_x, y_start, y_end,
nb_y, swap_xy);

Expand Down
120 changes: 96 additions & 24 deletions test/src/test_atan2pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,111 @@ int main() {
show_special2_fp64(rvvlm_atan2pi, swap_xy,
"Special Value handling of this function");

x_start = 0.5;
x_end = 2.0;
nb_x = 10;
y_start = 0x1.0p-20;
y_end = 0x1.0p-15;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p0;
y_end = 0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = 0.5;
x_end = 2.0;
nb_x = 10;
y_start = 0x1.0p-5;
y_end = 0x1.0p5;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p1020;
y_end = 0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -2.0;
x_end = -0.5;
nb_x = 10;
y_start = 0x1.0p-5;
y_end = 0x1.0p5;
nb_y = 40;
x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p-1020;
y_end = 0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -10.0;
x_end = -10.0;
nb_x = 10;
y_start = -1.0e3;
y_end = 1.0e3;
nb_y = 400000;
x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p0;
y_end = 0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p1020;
y_end = 0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = 0x1.01p-1020;
y_end = 0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p0;
y_end = -0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p1020;
y_end = -0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = 0x1.000000001p0;
x_end = 0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p-1020;
y_end = -0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p0;
y_end = -0x1.fffp0;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p1020;
y_end = -0x1.ffffffffp1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

x_start = -0x1.000000001p0;
x_end = -0x1.ffffffffffp0;
nb_x = 8;
y_start = -0x1.01p-1020;
y_end = -0x1.ffffffffp-1020;
nb_y = 1000000;
report_err2_fp64(rvvlm_atan2pi, atan2pil, x_start, x_end, nb_x, y_start,
y_end, nb_y, swap_xy);

Expand Down
4 changes: 2 additions & 2 deletions test/src/test_atanh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main() {

x_start = 0x1.0p-10;
x_end = 0x1.ffp-3;
nb_tests = 400000;
nb_tests = 4000000;
report_err_fp64(rvvlm_atanh, atanhl, x_start, x_end, nb_tests);

x_start = 0x1.00p-9;
Expand All @@ -46,7 +46,7 @@ int main() {

x_start = 0x1.0p-1;
x_end = 0x1.0p0 - 0x1.0p-51;
nb_tests = 400000;
nb_tests = 4000000;
report_err_fp64(rvvlm_atanh, atanhl, x_start, x_end, nb_tests);

x_start = -0x1.0p-1;
Expand Down
Loading

0 comments on commit c51869d

Please sign in to comment.