From: Daniel Lehman dlehman25@gmail.com
--- dlls/msvcr120/msvcr120.spec | 2 +- dlls/msvcr120_app/msvcr120_app.spec | 2 +- dlls/ucrtbase/tests/misc.c | 56 +++++++++++++++++++++++++++++ dlls/ucrtbase/ucrtbase.spec | 2 +- include/msvcrt/complex.h | 1 + libs/musl/Makefile.in | 1 + libs/musl/src/complex/carg.c | 6 ++++ 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 libs/musl/src/complex/carg.c
diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 4305bc7bada..438256b72a2 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -2047,7 +2047,7 @@ @ stub cacoshl @ stub cacosl @ cdecl calloc(long long) -@ stub carg +@ cdecl carg(int128) @ stub cargf @ stub cargl @ stub casin diff --git a/dlls/msvcr120_app/msvcr120_app.spec b/dlls/msvcr120_app/msvcr120_app.spec index c7cfe4e071e..a156ff84678 100644 --- a/dlls/msvcr120_app/msvcr120_app.spec +++ b/dlls/msvcr120_app/msvcr120_app.spec @@ -1714,7 +1714,7 @@ @ stub cacoshl @ stub cacosl @ cdecl calloc(long long) msvcr120.calloc -@ stub carg +@ cdecl carg(int128) msvcr120.carg @ stub cargf @ stub cargl @ stub casin diff --git a/dlls/ucrtbase/tests/misc.c b/dlls/ucrtbase/tests/misc.c index edd60473fc9..351de952c86 100644 --- a/dlls/ucrtbase/tests/misc.c +++ b/dlls/ucrtbase/tests/misc.c @@ -2000,6 +2000,61 @@ static void test_cexp(void) __setusermatherr(NULL); }
+static void test_carg(void) +{ + const double M_PI_3_4 = M_PI_2 + M_PI_4; + static const struct { + double r, i, expect; + } tests[] = { + { NAN, NAN, NAN }, + { INFINITY, 2.0, 0.0 }, + { INFINITY, -2.0, -0.0 }, + { 10.0, INFINITY, M_PI_2 }, + { 10.0, -INFINITY, -M_PI_2 }, + { -INFINITY, 10.0, M_PI }, + { -INFINITY, -10.0, -M_PI }, + { INFINITY, -INFINITY, -M_PI_4 }, + { -INFINITY, INFINITY, M_PI_3_4 }, + { INFINITY, INFINITY, M_PI_4 }, + { -INFINITY, -INFINITY, -M_PI_3_4 }, + { 2.0, 0.0, 0.0 }, + { 2.0, -0.0, -0.0 }, + { 0.0, 0.0, 0.0 }, + { 0.0, -0.0, -0.0 }, + { -2.0, 0.0, M_PI }, + { -2.0, -0.0, -M_PI }, + { -0.0, 0.0, M_PI }, + { -0.0, -0.0, -M_PI }, + { 0.0, 2.0, M_PI_2 }, + { -0.0, 2.0, M_PI_2 }, + { 0.0, -2.0, -M_PI_2 }, + { -0.0, -2.0, -M_PI_2 }, + }; + _Dcomplex c; + errno_t e; + double z; + int i; + + __setusermatherr(matherr_callback); + + for(i=0; i<ARRAY_SIZE(tests); i++) { + c = _Cbuild(tests[i].r, tests[i].i); + errno = -1; + exception.type = -1; + z = carg(c); + e = errno; + + ok(compare_double(z, tests[i].expect, 0), + "expected %0.16e, got %0.16e for %d\n", tests[i].expect, z, i); + ok(signbit(z) == signbit(tests[i].expect), "expected sign %x, got %x for %d\n", + signbit(tests[i].expect), signbit(z), i); + + ok(e == -1, "expected errno -1, but got %d for %d\n", e, i); + ok(exception.type == -1, "expected -1, got %d for %d\n", exception.type, i); + } + + __setusermatherr(NULL); +}
START_TEST(misc) { @@ -2051,4 +2106,5 @@ START_TEST(misc) test_exp(); test_expf(); test_cexp(); + test_carg(); } diff --git a/dlls/ucrtbase/ucrtbase.spec b/dlls/ucrtbase/ucrtbase.spec index 9f026b351d1..6c323e90313 100644 --- a/dlls/ucrtbase/ucrtbase.spec +++ b/dlls/ucrtbase/ucrtbase.spec @@ -2192,7 +2192,7 @@ @ stub cacoshl @ stub cacosl @ cdecl calloc(long long) -@ stub carg +@ cdecl carg(int128) @ stub cargf @ stub cargl @ stub casin diff --git a/include/msvcrt/complex.h b/include/msvcrt/complex.h index 78ddaf5088c..a179bb2ebee 100644 --- a/include/msvcrt/complex.h +++ b/include/msvcrt/complex.h @@ -27,6 +27,7 @@ typedef _C_float_complex _Fcomplex; _ACRTIMP _Dcomplex __cdecl _Cbuild(double, double); _ACRTIMP _Dcomplex __cdecl cexp(_Dcomplex);
+_ACRTIMP double __cdecl carg(_Dcomplex); _ACRTIMP double __cdecl cimag(_Dcomplex); _ACRTIMP double __cdecl creal(_Dcomplex);
diff --git a/libs/musl/Makefile.in b/libs/musl/Makefile.in index aed423e29b8..0b4f8fad5a4 100644 --- a/libs/musl/Makefile.in +++ b/libs/musl/Makefile.in @@ -5,6 +5,7 @@ EXTRADEFS = -D_ACRTIMP= -D_NO_CRT_MATH_INLINE \
SOURCES = \ src/complex/__cexp.c \ + src/complex/carg.c \ src/complex/cexp.c \ src/math/__cos.c \ src/math/__cosdf.c \ diff --git a/libs/musl/src/complex/carg.c b/libs/musl/src/complex/carg.c new file mode 100644 index 00000000000..289b1ad21a1 --- /dev/null +++ b/libs/musl/src/complex/carg.c @@ -0,0 +1,6 @@ +#include "complex_impl.h" + +double carg(_Dcomplex z) +{ + return atan2(cimag(z), creal(z)); +}