Skip to content

Commit

Permalink
Rename free function real_part and imag_part to real and imag
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Dec 22, 2024
1 parent 963e1a3 commit 3ac0205
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ Then, select one of the following targets and `make` it according to your purpos

| Target | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.5.304.so` and executable `meevax`.
| `all` | Build shared-library `libmeevax.0.5.305.so` and executable `meevax`.
| `install` | Copy files into `/usr/local` directly.
| `package` | Generate debian package `meevax_0.5.304_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.304_amd64.deb`.
| `package` | Generate debian package `meevax_0.5.305_amd64.deb` (only Ubuntu). The generated package can be installed by `sudo apt install build/meevax_0.5.305_amd64.deb`.
| `test` | Test executable `meevax`. This target requires Valgrind to be installed.
| `uninstall` | Remove files copied to `/usr/local` directly by target `install`.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.304
0.5.305
8 changes: 0 additions & 8 deletions include/meevax/kernel/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ namespace meevax::inline kernel
};

auto operator <<(std::ostream &, complex const&) -> std::ostream &;

auto real_part(object const&) -> object const&;

auto imag_part(object const&) -> object const&;

auto magnitude(object const&) -> object;

auto angle(object const&) -> object;
} // namespace meevax::kernel

#endif // INCLUDED_MEEVAX_KERNEL_COMPLEX_HPP
8 changes: 8 additions & 0 deletions include/meevax/kernel/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ inline namespace number

auto pow(object const&, object const&) -> object;

auto real(object const&) -> object;

auto imag(object const&) -> object;

auto magnitude(object const&) -> object;

auto angle(object const&) -> object;

auto numerator(object const&) -> object;

auto denominator(object const&) -> object;
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/boot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ namespace meevax::inline kernel

EXPORT1(angle);
EXPORT1(magnitude);
EXPORT1_RENAME(imag_part, "imag-part");
EXPORT1_RENAME(real_part, "real-part");
EXPORT1_RENAME(imag, "imag-part");
EXPORT1_RENAME(real, "real-part");
});

define<library>("(meevax context)", [](library & library)
Expand Down
27 changes: 0 additions & 27 deletions src/kernel/complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,31 +140,4 @@ namespace meevax::inline kernel
return os << z.real() << cyan(explicitly_signed(z.imag()), "i");
}
}

auto real_part(object const& x) -> object const&
{
return x.is<complex>() ? car(x) : x;
}

auto imag_part(object const& x) -> object const&
{
return x.is<complex>() ? cdr(x) : e0;
}

auto magnitude(object const& x) -> object
{
auto hypotenuse = [](let const& x, let const& y)
{
return sqrt(x * x + y * y);
};

return hypotenuse(real_part(x),
imag_part(x));
}

auto angle(object const& x) -> object
{
return atan2(real_part(x),
imag_part(x));
}
} // namespace meevax::kernel
56 changes: 56 additions & 0 deletions src/kernel/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,62 @@ inline namespace number
return apply_to<complex_numbers>(f, x, y);
}

auto real(object const& x) -> object
{
auto f = []<typename T>(T const& x)
{
if constexpr (std::is_same_v<T, complex>)
{
return x.real();
}
else
{
return x;
}
};

return apply_to<complex_number>(f, x);
}

auto imag(object const& x) -> object
{
auto f = []<typename T>(T const& x)
{
if constexpr (std::is_same_v<T, complex>)
{
return x.imag();
}
else
{
return e0;
}
};

return apply_to<complex_number>(f, x);
}

auto magnitude(object const& x) -> object
{
auto f = []<typename T>(T const& x)
{
if constexpr (std::is_same_v<T, complex>)
{
return sqrt(x.real() * x.real() + x.imag() * x.imag());
}
else
{
return x;
}
};

return apply_to<complex_number>(f, x);
}

auto angle(object const& x) -> object
{
return atan2(real(x), imag(x));
}

auto numerator(object const& x) -> object
{
if (x.is<ratio>())
Expand Down

0 comments on commit 3ac0205

Please sign in to comment.