Skip to content

Commit

Permalink
string literal _percentage added
Browse files Browse the repository at this point in the history
  • Loading branch information
iarfen committed Aug 12, 2024
1 parent aa8fa3e commit 9c8622a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/units/test_unit_abbreviation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ TEST_CASE("Abbreviation literals") {
CHECK(bool(to_string(5_rad) == "286.47°"));
CHECK(bool(100_particles == "100 particles"));
CHECK(bool(100_particles == "100 particles"));
CHECK(bool(30_percentage == "30%"));
CHECK(bool(100_ppm == "100 ppm"));
/*CHECK(bool(100_ppb == "100 ppb"));
CHECK(bool(100_ppt == "100 ppt"));
Expand Down Expand Up @@ -415,6 +416,7 @@ TEST_CASE("Abbreviation literals") {
CHECK(bool(100.0_memo == "100 memo"));
CHECK(bool(100.0_degree == "100°"));
CHECK(bool(to_string(5.0_rad) == "286.47°"));
CHECK(bool(30.0_percentage == "30%"));
CHECK(bool(100.0_ppm == "100 ppm"));
/*CHECK(bool(100.0_ppb == "100 ppb"));
CHECK(bool(100.0_ppt == "100 ppt"));
Expand Down
10 changes: 10 additions & 0 deletions units/unit_abbreviation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,11 @@ scifir::angle operator"" _rad(unsigned long long int x)
return scifir::angle((long double)x, scifir::angle::RADIAN);
}

scifir::percentage operator"" _percentage(unsigned long long int x)
{
return scifir::percentage((long double)x, scifir::percentage::PERCENTAGE);
}

scifir::percentage operator"" _ppm(unsigned long long int x)
{
return scifir::percentage((long double)x, scifir::percentage::PARTS_PER_MILLION);
Expand Down Expand Up @@ -1887,6 +1892,11 @@ scifir::angle operator"" _rad(long double x)
return scifir::angle(x, scifir::angle::RADIAN);
}

scifir::percentage operator"" _percentage(long double x)
{
return scifir::percentage(x, scifir::percentage::PERCENTAGE);
}

scifir::percentage operator"" _ppm(long double x)
{
return scifir::percentage(x, scifir::percentage::PARTS_PER_MILLION);
Expand Down
2 changes: 2 additions & 0 deletions units/unit_abbreviation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ scifir::mole operator"" _particles(unsigned long long int);
scifir::scalar_unit operator"" _memo(unsigned long long int);
scifir::angle operator"" _degree(unsigned long long int);
scifir::angle operator"" _rad(unsigned long long int);
scifir::percentage operator"" _percentage(unsigned long long int);
scifir::percentage operator"" _ppm(unsigned long long int);
/*scifir::percentage operator"" _ppb(unsigned long long int);
scifir::percentage operator"" _ppt(unsigned long long int);
Expand Down Expand Up @@ -419,6 +420,7 @@ scifir::scalar_unit operator"" _mEq(long double);
scifir::scalar_unit operator"" _memo(long double);
scifir::angle operator"" _degree(long double);
scifir::angle operator"" _rad(long double);
scifir::percentage operator"" _percentage(long double);
scifir::percentage operator"" _ppm(long double);
/*scifir::percentage operator"" _ppb(long double);
scifir::percentage operator"" _ppt(long double);
Expand Down

0 comments on commit 9c8622a

Please sign in to comment.