Skip to content

Commit ab1e884

Browse files
committed
Restrict fixed_point_t constructor to integral_max_size_4
1 parent 26205ac commit ab1e884

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/openvic-simulation/economy/BuildingInstance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ void BuildingInstance::update_gamestate(Date today) {
3232
end_date = start_date + building_type.get_build_time();
3333
break;
3434
case ExpansionState::Expanding:
35-
expansion_progress = fixed_point_t { static_cast<int32_t>((today - start_date).to_int()) } / (end_date - start_date).to_int();
35+
expansion_progress = fixed_point_t { static_cast<int32_t>((today - start_date).to_int()) }
36+
/ static_cast<int32_t>((end_date - start_date).to_int());
3637
break;
3738
default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand;
3839
}

src/openvic-simulation/types/fixed_point/FixedPoint.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <cassert>
4-
#include <cctype>
54
#include <charconv>
65
#include <concepts>
76
#include <cstddef>
@@ -78,7 +77,8 @@ namespace OpenVic {
7877

7978
public:
8079
OV_ALWAYS_INLINE constexpr fixed_point_t() : value { 0 } {}
81-
OV_ALWAYS_INLINE constexpr fixed_point_t(int32_t new_value) : value { static_cast<value_type>(new_value) << PRECISION } {}
80+
template<integral_max_size_4 T>
81+
OV_ALWAYS_INLINE constexpr fixed_point_t(T new_value) : value { static_cast<value_type>(new_value) << PRECISION } {}
8282

8383
static const fixed_point_t max;
8484
static const fixed_point_t min;
@@ -238,7 +238,7 @@ namespace OpenVic {
238238
return truncate();
239239
}
240240

241-
return floor<value_type>();
241+
return parse_raw(floor<value_type>());
242242
}
243243

244244
template<std::integral T>
@@ -255,7 +255,7 @@ namespace OpenVic {
255255
return truncate();
256256
}
257257

258-
return ceil<value_type>();
258+
return parse_raw(ceil<value_type>());
259259
}
260260

261261
OV_SPEED_INLINE constexpr fixed_point_t round() const {

0 commit comments

Comments
 (0)