Skip to content

Commit

Permalink
Add identity operator for number.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Sep 13, 2023
1 parent dd271ce commit 475489b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/heyoka/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ HEYOKA_DLL_PUBLIC bool is_negative_one(const number &);
HEYOKA_DLL_PUBLIC bool is_negative(const number &);
HEYOKA_DLL_PUBLIC bool is_integer(const number &);

HEYOKA_DLL_PUBLIC number operator+(number);
HEYOKA_DLL_PUBLIC number operator-(const number &);

HEYOKA_DLL_PUBLIC number operator+(const number &, const number &);
Expand Down
31 changes: 31 additions & 0 deletions test/number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,34 @@ TEST_CASE("move semantics")
REQUIRE(x3 == number{3.});
REQUIRE(x2 == number{0.});
}

TEST_CASE("basic arith")
{
number n{42.};

REQUIRE(+n == n);
REQUIRE(-n == number{-42.});
}

TEST_CASE("copy assignment")
{
number n1{42.};
number n2{42.f};

n2 = n1;

REQUIRE(n2 == number{42.});
}

TEST_CASE("swap")
{
REQUIRE(std::is_nothrow_swappable_v<number>);

number n1{42.};
number n2{42.f};

swap(n1, n2);

REQUIRE(n2 == number{42.});
REQUIRE(n1 == number{42.f});
}

0 comments on commit 475489b

Please sign in to comment.