mirror of
https://github.com/c3d/DB48X-on-DM42.git
synced 2024-09-28 03:20:53 +02:00
complex: Return an angle from arg
function
The `arg` function now returns an angle in current angle mode. Fixes: #1149 Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
parent
c6068d1c37
commit
985b8a4619
2 changed files with 45 additions and 18 deletions
|
@ -556,11 +556,20 @@ FUNCTION_BODY(arg)
|
|||
if (should_be_symbolic(xt))
|
||||
return symbolic(ID_arg, x);
|
||||
auto angle_mode = Settings.AngleMode();
|
||||
algebraic_g a;
|
||||
if (is_complex(xt))
|
||||
return complex_p(algebraic_p(x))->arg(angle_mode);
|
||||
algebraic_g zero = integer::make(0);
|
||||
bool negative = x->is_negative(false);
|
||||
return complex::convert_angle(zero, angle_mode, angle_mode, negative);
|
||||
{
|
||||
a = complex_p(algebraic_p(x))->arg(angle_mode);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool negative = x->is_negative(false);
|
||||
a = integer::make(0);
|
||||
a = complex::convert_angle(a, angle_mode, angle_mode, negative);
|
||||
}
|
||||
if (a && Settings.SetAngleUnits() && a->is_real())
|
||||
add_angle(a);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
|
46
src/tests.cc
46
src/tests.cc
|
@ -170,7 +170,7 @@ void tests::run(uint onlyCurrent)
|
|||
{
|
||||
here().begin("Current");
|
||||
if (onlyCurrent & 1)
|
||||
for_loops();
|
||||
complex_functions();
|
||||
if (onlyCurrent & 2)
|
||||
demo_ui();
|
||||
if (onlyCurrent & 4)
|
||||
|
@ -4675,15 +4675,6 @@ void tests::complex_functions()
|
|||
test(CLEAR, "3+4ⅈ modulus", ENTER).expect("5.");
|
||||
test(CLEAR, "a+bⅈ modulus", ENTER).expect("'a⊿b'");
|
||||
|
||||
step("Complex argument");
|
||||
test(CLEAR, "1+1ⅈ arg", ENTER).expect("0.78539 81633 97448 30962");
|
||||
step("Symbolic complex argument");
|
||||
test(CLEAR, "a+bⅈ arg", ENTER).expect("'b∠a'");
|
||||
step("Complex argument on integers");
|
||||
test(CLEAR, "31 arg", ENTER).expect("0");
|
||||
step("Complex argument on decimals");
|
||||
test(CLEAR, "31.234 arg", ENTER).expect("0");
|
||||
|
||||
step("Complex conjugate");
|
||||
test(CLEAR, "3+4ⅈ conj", ENTER).expect("3-4ⅈ");
|
||||
step("Symbolic complex conjugate");
|
||||
|
@ -4693,6 +4684,33 @@ void tests::complex_functions()
|
|||
step("Complex conjugate on decimals");
|
||||
test(CLEAR, "31.234 conj", ENTER).expect("31.234");
|
||||
|
||||
step("Complex argument");
|
||||
test(CLEAR, "1+1ⅈ arg", ENTER).expect("0.78539 81633 97448 30962 r");
|
||||
step("Symbolic complex argument");
|
||||
test(CLEAR, "a+bⅈ arg", ENTER).expect("'b∠a'");
|
||||
step("Complex argument on integers");
|
||||
test(CLEAR, "31 arg", ENTER).expect("0 r");
|
||||
step("Complex argument on decimals");
|
||||
test(CLEAR, "31.234 arg", ENTER).expect("0 r");
|
||||
step("Complex argument on negative integers");
|
||||
test(CLEAR, "-31 arg", ENTER).expect("3.14159 26535 89793 2385 r");
|
||||
step("Complex argument on negative decimals");
|
||||
test(CLEAR, "-31.234 arg", ENTER).expect("3.14159 26535 89793 2385 r");
|
||||
|
||||
step("Complex argument in degrees");
|
||||
test(CLEAR, "DEG", ENTER);
|
||||
test(CLEAR, "1+1ⅈ arg", ENTER).expect("45 °");
|
||||
step("Symbolic complex argument in degrees");
|
||||
test(CLEAR, "a+bⅈ arg", ENTER).expect("'b∠a'");
|
||||
step("Complex argument on integers in degrees");
|
||||
test(CLEAR, "31 arg", ENTER).expect("0 °");
|
||||
step("Complex argument on decimals in degrees");
|
||||
test(CLEAR, "31.234 arg", ENTER).expect("0 °");
|
||||
test(CLEAR, "-31 arg", ENTER).expect("180 °");
|
||||
step("Complex argument on decimals in degrees");
|
||||
test(CLEAR, "-31.234 arg", ENTER).expect("180 °");
|
||||
test(CLEAR, "RAD", ENTER);
|
||||
|
||||
step("Restore default 24-digit precision");
|
||||
test(CLEAR, "24 PRECISION 12 SIG", ENTER).noerror();
|
||||
}
|
||||
|
@ -8785,13 +8803,13 @@ void tests::regression_checks()
|
|||
test(CLEAR, "'x' #2134AF AND", ENTER).error("Bad argument type");
|
||||
|
||||
step("Bug 277: 1+i should have positive arg");
|
||||
test(CLEAR, "1+1ⅈ arg", ENTER).expect("45");
|
||||
test(CLEAR, "1-1ⅈ arg", ENTER).expect("-45");
|
||||
test(CLEAR, "1 1 atan2", ENTER).expect("45");
|
||||
test(CLEAR, "1+1ⅈ arg", ENTER).expect("45 °");
|
||||
test(CLEAR, "1-1ⅈ arg", ENTER).expect("-45 °");
|
||||
test(CLEAR, "1 1 atan2", ENTER).expect("45 °");
|
||||
test(CLEAR, "1+1ⅈ ToPolar", ENTER).match("1.414.*∡45°");
|
||||
|
||||
step("Bug 287: arg of negative number");
|
||||
test(CLEAR, "-35 arg", ENTER).expect("180");
|
||||
test(CLEAR, "-35 arg", ENTER).expect("180 °");
|
||||
|
||||
step("Bug 288: Abusive simplification of multiplication by -1");
|
||||
test(CLEAR, "-1 3 *", ENTER).expect("-3");
|
||||
|
|
Loading…
Reference in a new issue