diff --git a/test/testautomation_math.c b/test/testautomation_math.c index d8b53f6e9..1d39eaa5f 100644 --- a/test/testautomation_math.c +++ b/test/testautomation_math.c @@ -102,8 +102,15 @@ helper_dtod_inexact(const char *func_name, d_to_d_func func, Uint32 i; for (i = 0; i < cases_size; i++) { const double result = func(cases[i].input); - SDLTest_AssertCheck(result >= cases[i].expected - EPSILON && - result <= cases[i].expected + EPSILON, + double diff = result - cases[i].expected; + double max_err = (cases[i].expected + 1.) * EPSILON; + if (diff < 0) { + diff = -diff; + } + if (max_err < 0) { + max_err = -max_err; + } + SDLTest_AssertCheck(diff <= max_err, "%s(%f), expected [%f,%f], got %f", func_name, cases[i].input, @@ -157,8 +164,16 @@ helper_ddtod_inexact(const char *func_name, dd_to_d_func func, Uint32 i; for (i = 0; i < cases_size; i++) { const double result = func(cases[i].x_input, cases[i].y_input); - SDLTest_AssertCheck(result >= cases[i].expected - EPSILON && - result <= cases[i].expected + EPSILON, + double diff = result - cases[i].expected; + double max_err = (cases[i].expected + 1.) * EPSILON; + if (diff < 0) { + diff = -diff; + } + if (max_err < 0) { + max_err = -max_err; + } + + SDLTest_AssertCheck(diff <= max_err, "%s(%f,%f), expected [%f,%f], got %f", func_name, cases[i].x_input, cases[i].y_input, @@ -1655,7 +1670,7 @@ pow_regularCases(void *args) { 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 }, { 478.972, 12.125, 315326359630449587856007411793920.0 } }; - return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases)); + return helper_ddtod_inexact("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases)); } /** @@ -1983,24 +1998,24 @@ static int cos_precisionTest(void *args) { const d_to_d precision_cases[] = { - { M_PI * 1.0 / 10.0, 0.9510565162 }, - { M_PI * 2.0 / 10.0, 0.8090169943 }, - { M_PI * 3.0 / 10.0, 0.5877852522 }, - { M_PI * 4.0 / 10.0, 0.3090169943 }, + { M_PI * 1.0 / 10.0, 0.9510565162951535 }, + { M_PI * 2.0 / 10.0, 0.8090169943749475 }, + { M_PI * 3.0 / 10.0, 0.5877852522924731 }, + { M_PI * 4.0 / 10.0, 0.30901699437494745 }, { M_PI * 5.0 / 10.0, 0.0 }, - { M_PI * 6.0 / 10.0, -0.3090169943 }, - { M_PI * 7.0 / 10.0, -0.5877852522 }, - { M_PI * 8.0 / 10.0, -0.8090169943 }, - { M_PI * 9.0 / 10.0, -0.9510565162 }, - { M_PI * -1.0 / 10.0, 0.9510565162 }, - { M_PI * -2.0 / 10.0, 0.8090169943 }, - { M_PI * -3.0 / 10.0, 0.5877852522 }, - { M_PI * -4.0 / 10.0, 0.3090169943 }, + { M_PI * 6.0 / 10.0, -0.30901699437494734 }, + { M_PI * 7.0 / 10.0, -0.587785252292473 }, + { M_PI * 8.0 / 10.0, -0.8090169943749473 }, + { M_PI * 9.0 / 10.0, -0.9510565162951535 }, + { M_PI * -1.0 / 10.0, 0.9510565162951535 }, + { M_PI * -2.0 / 10.0, 0.8090169943749475 }, + { M_PI * -3.0 / 10.0, 0.5877852522924731 }, + { M_PI * -4.0 / 10.0, 0.30901699437494745 }, { M_PI * -5.0 / 10.0, 0.0 }, - { M_PI * -6.0 / 10.0, -0.3090169943 }, - { M_PI * -7.0 / 10.0, -0.5877852522 }, - { M_PI * -8.0 / 10.0, -0.8090169943 }, - { M_PI * -9.0 / 10.0, -0.9510565162 } + { M_PI * -6.0 / 10.0, -0.30901699437494734 }, + { M_PI * -7.0 / 10.0, -0.587785252292473 }, + { M_PI * -8.0 / 10.0, -0.8090169943749473 }, + { M_PI * -9.0 / 10.0, -0.9510565162951535 } }; return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases)); } @@ -2101,23 +2116,23 @@ static int sin_precisionTest(void *args) { const d_to_d precision_cases[] = { - { M_PI * 1.0 / 10.0, 0.3090169943 }, - { M_PI * 2.0 / 10.0, 0.5877852522 }, - { M_PI * 3.0 / 10.0, 0.8090169943 }, - { M_PI * 4.0 / 10.0, 0.9510565162 }, - { M_PI * 6.0 / 10.0, 0.9510565162 }, - { M_PI * 7.0 / 10.0, 0.8090169943 }, - { M_PI * 8.0 / 10.0, 0.5877852522 }, - { M_PI * 9.0 / 10.0, 0.3090169943 }, + { M_PI * 1.0 / 10.0, 0.3090169943749474 }, + { M_PI * 2.0 / 10.0, 0.5877852522924731 }, + { M_PI * 3.0 / 10.0, 0.8090169943749475 }, + { M_PI * 4.0 / 10.0, 0.9510565162951535 }, + { M_PI * 6.0 / 10.0, 0.9510565162951536 }, + { M_PI * 7.0 / 10.0, 0.8090169943749475 }, + { M_PI * 8.0 / 10.0, 0.5877852522924732 }, + { M_PI * 9.0 / 10.0, 0.3090169943749475 }, { M_PI, 0.0 }, - { M_PI * -1.0 / 10.0, -0.3090169943 }, - { M_PI * -2.0 / 10.0, -0.5877852522 }, - { M_PI * -3.0 / 10.0, -0.8090169943 }, - { M_PI * -4.0 / 10.0, -0.9510565162 }, - { M_PI * -6.0 / 10.0, -0.9510565162 }, - { M_PI * -7.0 / 10.0, -0.8090169943 }, - { M_PI * -8.0 / 10.0, -0.5877852522 }, - { M_PI * -9.0 / 10.0, -0.3090169943 }, + { M_PI * -1.0 / 10.0, -0.3090169943749474 }, + { M_PI * -2.0 / 10.0, -0.5877852522924731 }, + { M_PI * -3.0 / 10.0, -0.8090169943749475 }, + { M_PI * -4.0 / 10.0, -0.9510565162951535 }, + { M_PI * -6.0 / 10.0, -0.9510565162951536 }, + { M_PI * -7.0 / 10.0, -0.8090169943749475 }, + { M_PI * -8.0 / 10.0, -0.5877852522924732 }, + { M_PI * -9.0 / 10.0, -0.3090169943749475 }, { -M_PI, 0.0 }, }; return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases)); @@ -2217,26 +2232,26 @@ static int tan_precisionTest(void *args) { const d_to_d precision_cases[] = { - { M_PI * 1.0 / 11.0, 0.2936264929 }, - { M_PI * 2.0 / 11.0, 0.6426609771 }, - { M_PI * 3.0 / 11.0, 1.1540615205 }, - { M_PI * 4.0 / 11.0, 2.1896945629 }, - { M_PI * 5.0 / 11.0, 6.9551527717 }, - { M_PI * 6.0 / 11.0, -6.9551527717 }, - { M_PI * 7.0 / 11.0, -2.1896945629 }, - { M_PI * 8.0 / 11.0, -1.1540615205 }, - { M_PI * 9.0 / 11.0, -0.6426609771 }, - { M_PI * 10.0 / 11.0, -0.2936264929 }, - { M_PI * -1.0 / 11.0, -0.2936264929 }, - { M_PI * -2.0 / 11.0, -0.6426609771 }, - { M_PI * -3.0 / 11.0, -1.1540615205 }, - { M_PI * -4.0 / 11.0, -2.1896945629 }, - { M_PI * -5.0 / 11.0, -6.9551527717 }, - { M_PI * -6.0 / 11.0, 6.9551527717 }, - { M_PI * -7.0 / 11.0, 2.1896945629 }, - { M_PI * -8.0 / 11.0, 1.1540615205 }, - { M_PI * -9.0 / 11.0, 0.6426609771 }, - { M_PI * -10.0 / 11.0, 0.2936264929 } + { M_PI * 1.0 / 11.0, 0.29362649293836673 }, + { M_PI * 2.0 / 11.0, 0.642660977168331 }, + { M_PI * 3.0 / 11.0, 1.1540615205330094 }, + { M_PI * 4.0 / 11.0, 2.189694562989681 }, + { M_PI * 5.0 / 11.0, 6.9551527717734745 }, + { M_PI * 6.0 / 11.0, -6.955152771773481 }, + { M_PI * 7.0 / 11.0, -2.189694562989682 }, + { M_PI * 8.0 / 11.0, -1.1540615205330096 }, + { M_PI * 9.0 / 11.0, -0.6426609771683314 }, + { M_PI * 10.0 / 11.0, -0.2936264929383667 }, + { M_PI * -1.0 / 11.0, -0.29362649293836673 }, + { M_PI * -2.0 / 11.0, -0.642660977168331 }, + { M_PI * -3.0 / 11.0, -1.1540615205330094 }, + { M_PI * -4.0 / 11.0, -2.189694562989681 }, + { M_PI * -5.0 / 11.0, -6.9551527717734745 }, + { M_PI * -6.0 / 11.0, 6.955152771773481 }, + { M_PI * -7.0 / 11.0, 2.189694562989682 }, + { M_PI * -8.0 / 11.0, 1.1540615205330096 }, + { M_PI * -9.0 / 11.0, 0.6426609771683314 }, + { M_PI * -10.0 / 11.0, 0.2936264929383667 } }; return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases)); } @@ -2401,26 +2416,26 @@ static int asin_precisionTest(void *args) { const d_to_d precision_cases[] = { - { 0.9, 1.1197695149 }, - { 0.8, 0.9272952180 }, - { 0.7, 0.7753974966 }, - { 0.6, 0.6435011087 }, - { 0.5, 0.5235987755 }, - { 0.4, 0.4115168460 }, - { 0.3, 0.3046926540 }, - { 0.2, 0.2013579207 }, - { 0.1, 0.1001674211 }, + { 0.9, 1.1197695149986342 }, + { 0.8, 0.9272952180016123 }, + { 0.7, 0.775397496610753 }, + { 0.6, 0.6435011087932844 }, + { 0.5, 0.5235987755982989 }, + { 0.4, 0.41151684606748806 }, + { 0.3, 0.3046926540153976 }, + { 0.2, 0.20135792079033074 }, + { 0.1, 0.10016742116155977 }, { 0.0, 0.0 }, { -0.0, -0.0 }, - { -0.1, -0.1001674211 }, - { -0.2, -0.2013579207 }, - { -0.3, -0.3046926540 }, - { -0.4, -0.4115168460 }, - { -0.5, -0.5235987755 }, - { -0.6, -0.6435011087 }, - { -0.7, -0.7753974966 }, - { -0.8, -0.9272952180 }, - { -0.9, -1.1197695149 } + { -0.1, -0.10016742116155977 }, + { -0.2, -0.20135792079033074 }, + { -0.3, -0.3046926540153976 }, + { -0.4, -0.41151684606748806 }, + { -0.5, -0.5235987755982989 }, + { -0.6, -0.6435011087932844 }, + { -0.7, -0.775397496610753 }, + { -0.8, -0.9272952180016123 }, + { -0.9, -1.1197695149986342 } }; return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases)); } @@ -2495,24 +2510,24 @@ static int atan_precisionTest(void *args) { const d_to_d precision_cases[] = { - { 6.313751514675041, 1.4137166941 }, - { 3.0776835371752527, 1.2566370614 }, - { 1.9626105055051504, 1.0995574287 }, - { 1.3763819204711734, 0.9424777960 }, - { 1.0, 0.7853981633 }, - { 0.7265425280053609, 0.6283185307 }, - { 0.5095254494944288, 0.4712388980 }, - { 0.3249196962329063, 0.3141592653 }, - { 0.15838444032453627, 0.1570796326 }, - { -0.15838444032453627, -0.1570796326 }, - { -0.3249196962329063, -0.3141592653 }, - { -0.5095254494944288, -0.4712388980 }, - { -0.7265425280053609, -0.6283185307 }, - { -1.0, -0.7853981633 }, - { -1.3763819204711734, -0.9424777960 }, - { -1.9626105055051504, -1.0995574287 }, - { -3.0776835371752527, -1.2566370614 }, - { -6.313751514675041, -1.4137166941 }, + { 6.313751514675041, 1.413716694115407 }, + { 3.0776835371752527, 1.2566370614359172 }, + { 1.9626105055051504, 1.0995574287564276 }, + { 1.3763819204711734, 0.9424777960769379 }, + { 1.0, 0.7853981633974483 }, + { 0.7265425280053609, 0.6283185307179586 }, + { 0.5095254494944288, 0.47123889803846897 }, + { 0.3249196962329063, 0.3141592653589793 }, + { 0.15838444032453627, 0.15707963267948966 }, + { -0.15838444032453627, -0.15707963267948966 }, + { -0.3249196962329063, -0.3141592653589793 }, + { -0.5095254494944288, -0.47123889803846897 }, + { -0.7265425280053609, -0.6283185307179586 }, + { -1.0, -0.7853981633974483 }, + { -1.3763819204711734, -0.9424777960769379 }, + { -1.9626105055051504, -1.0995574287564276 }, + { -3.0776835371752527, -1.2566370614359172 }, + { -6.313751514675041, -1.413716694115407 }, }; return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases)); }