Skip to content

Commit

Permalink
fix level -4
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Oct 27, 2024
1 parent 2c9bf3d commit ab16a3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/osr/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ constexpr direction to_direction(std::string_view s) {
// level
using level_t = cista::strong<std::uint8_t, struct level_>;

// would be -4.0 as float but represented as NaN
constexpr auto const kNoLevel = level_t{0U};
constexpr auto const kMinLevel = -3.75F;
constexpr auto const kMaxLevel = 3.75F;
constexpr auto const kMinLevel = -4.0F;
constexpr auto const kMaxLevel = 3.5F;

constexpr level_t to_level(float const f) {
return level_t{static_cast<std::uint8_t>((f - kMinLevel) / 0.25F) + 1U};
Expand Down
3 changes: 3 additions & 0 deletions test/level_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ TEST(osr, level) {
auto const lvl_4 = to_float(to_level(4.0F));
EXPECT_EQ(4.0F, lvl_4);

auto const lvl_negative_4 = to_float(to_level(-4.0F));
EXPECT_EQ(-4.0F, lvl_negative_4);

auto const lvl_minus_3 = to_float(to_level(-3.0F));
EXPECT_EQ(-3.0F, lvl_minus_3);
}

0 comments on commit ab16a3e

Please sign in to comment.