diff --git a/bin/dc-1.0.5-1-x86_64.pkg.tar.zst b/bin/dc-1.0.5-1-x86_64.pkg.tar.zst deleted file mode 100644 index 8851aff..0000000 Binary files a/bin/dc-1.0.5-1-x86_64.pkg.tar.zst and /dev/null differ diff --git a/bin/dc-1.0.5-2.x86_64.rpm b/bin/dc-1.0.5-2.x86_64.rpm deleted file mode 100644 index f548b11..0000000 Binary files a/bin/dc-1.0.5-2.x86_64.rpm and /dev/null differ diff --git a/bin/dc-1.0.5.x86_64.deb b/bin/dc-1.0.5.x86_64.deb deleted file mode 100644 index ed0a077..0000000 Binary files a/bin/dc-1.0.5.x86_64.deb and /dev/null differ diff --git a/bin/dc-1.0.6-1-x86_64.pkg.tar.zst b/bin/dc-1.0.6-1-x86_64.pkg.tar.zst new file mode 100644 index 0000000..8a012b5 Binary files /dev/null and b/bin/dc-1.0.6-1-x86_64.pkg.tar.zst differ diff --git a/bin/dc-1.0.6-2.x86_64.rpm b/bin/dc-1.0.6-2.x86_64.rpm new file mode 100644 index 0000000..dc2cd64 Binary files /dev/null and b/bin/dc-1.0.6-2.x86_64.rpm differ diff --git a/bin/dc-1.0.6.x86_64.deb b/bin/dc-1.0.6.x86_64.deb new file mode 100644 index 0000000..7190d51 Binary files /dev/null and b/bin/dc-1.0.6.x86_64.deb differ diff --git a/man.md b/man.md index b3d8264..cfaaf62 100644 --- a/man.md +++ b/man.md @@ -3,7 +3,7 @@ title: dc section: 1 header: General Commands Manual footer: Marco Cetica -date: April 19, 2024 +date: April 22, 2024 --- @@ -238,7 +238,7 @@ $$ z = a + ib $$ -write the _real_ part($a$) into the _second-to-top_ of the stack, the _imaginary_ part($b$) into the `x` _head_ of the stack and then issue the `b` command. For example, to enter $(9 + 4i)$, write: +write the _real_ part($a$) into the _second-to-top_ of the stack, the _imaginary_ part($b$) into the _head_ of the stack and then issue the `b` command. For example, to enter $(9 + 4i)$, write: ``` 9 4 b p diff --git a/src/mathematics.cpp b/src/mathematics.cpp index 65657cf..33fd2b1 100644 --- a/src/mathematics.cpp +++ b/src/mathematics.cpp @@ -388,8 +388,30 @@ std::optional Mathematics::fn_exp(dc::Stack &stack, co auto exp = std::stod(stack.pop(true)); auto base = std::stod(stack.pop(true)); - // Push back the result as a string - stack.push(trim_digits(pow(base, exp), parameters.precision)); + std::complex power; + + // If base is positive or exponent is an integer + // calculate pow with real numbers. Otherwise + // with complex numbers + if(base > 0 || std::fmod(exp, 1.0) == 0) { + power = std::pow(base, exp); + } else { + power = std::pow(std::complex(base), exp); + } + + // Check if result is a complex number + if(std::imag(power) != 0) { + // trim their digits + auto real_trimmed = trim_digits(power.real(), parameters.precision); + auto imag_trimmed = trim_digits(power.imag(), parameters.precision); + auto complex_str = ('(' + real_trimmed + ',' + imag_trimmed + ')'); + + // Push the result back onto the stack + stack.push(complex_str); + } else { + // Push the result back onto the stack + stack.push(trim_digits(std::real(power), parameters.precision)); + } } else if(is_x_cmplx || is_y_cmplx) { stack.copy_xyz(); // Convert complex dc objects(ie strings) to std::complex