Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <limits>

#include <type_safe/strong_typedef.hpp>

Expand Down Expand Up @@ -1839,7 +1840,8 @@ void CountryInstance::update_gamestate(const Date today, MapInstance& map_instan
}

if (occupied_provinces_proportion != 0) {
occupied_provinces_proportion /= owned_provinces.size();
assert(owned_provinces.size() <= std::numeric_limits<int32_t>::max());
occupied_provinces_proportion /= static_cast<int32_t>(owned_provinces.size());
}

if (capital != nullptr) {
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/economy/BuildingInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void BuildingInstance::update_gamestate(Date today) {
end_date = start_date + building_type.get_build_time();
break;
case ExpansionState::Expanding:
expansion_progress = fixed_point_t { static_cast<int32_t>((today - start_date).to_int()) } / (end_date - start_date).to_int();
expansion_progress = fixed_point_t { static_cast<int32_t>((today - start_date).to_int()) }
/ static_cast<int32_t>((end_date - start_date).to_int());
break;
default: expansion_state = _can_expand() ? ExpansionState::CanExpand : ExpansionState::CannotExpand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ArtisanalProducerDeps.hpp"

#include <cstddef>
#include <limits>

#include <type_safe/strong_typedef.hpp>

Expand Down Expand Up @@ -521,6 +522,7 @@ ProductionType const* ArtisanalProducer::pick_production_type(
);

fixed_point_t relative_score = ranked_artisanal_production_types.empty() ? fixed_point_t::_1 : fixed_point_t::_0;
assert(ranked_artisanal_production_types.size() < std::numeric_limits<int32_t>::max());
for (auto it = ranked_artisanal_production_types.begin(); it < ranked_artisanal_production_types.end(); ++it) {
auto const& [production_type, score_estimate] = *it;
size_t i = it - ranked_artisanal_production_types.begin();
Expand All @@ -532,14 +534,15 @@ ProductionType const* ArtisanalProducer::pick_production_type(
relative_score = (
(current_score - score_estimate)
/ (previous_score_estimate - score_estimate)
+ ranked_artisanal_production_types.size() - i
) / (1 + ranked_artisanal_production_types.size());
+ static_cast<int32_t>(ranked_artisanal_production_types.size() - i)
) / static_cast<int32_t>(1 + ranked_artisanal_production_types.size());
}
break;
}

if (current_score == score_estimate) {
relative_score = fixed_point_t::parse(ranked_artisanal_production_types.size() - i) / (1 + ranked_artisanal_production_types.size());
relative_score = fixed_point_t::parse(ranked_artisanal_production_types.size() - i)
/ static_cast<int32_t>(1 + ranked_artisanal_production_types.size());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <cstdint>
#include <optional>

#include "openvic-simulation/types/IndexedFlatMap.hpp"
Expand Down Expand Up @@ -91,7 +92,7 @@ namespace OpenVic {
private:
CountryInstance* const country_to_report_economy_nullable;
memory::vector<fixed_point_t>& demand_per_input;
size_t distinct_goods_to_buy = 0;
int32_t distinct_goods_to_buy = 0;
Fraction inputs_bought_fraction;
MarketInstance const& market_instance;
memory::vector<fixed_point_t>& max_price_per_input;
Expand Down
8 changes: 4 additions & 4 deletions src/openvic-simulation/types/fixed_point/FixedPoint.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <cassert>
#include <cctype>
#include <charconv>
#include <concepts>
#include <cstddef>
Expand Down Expand Up @@ -78,7 +77,8 @@ namespace OpenVic {

public:
OV_ALWAYS_INLINE constexpr fixed_point_t() : value { 0 } {}
OV_ALWAYS_INLINE constexpr fixed_point_t(int32_t new_value) : value { static_cast<value_type>(new_value) << PRECISION } {}
template<integral_max_size_4 T>
OV_ALWAYS_INLINE constexpr fixed_point_t(T new_value) : value { static_cast<value_type>(new_value) << PRECISION } {}

static const fixed_point_t max;
static const fixed_point_t min;
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace OpenVic {
return truncate();
}

return floor<value_type>();
return floor<int32_t>();
}

template<std::integral T>
Expand All @@ -255,7 +255,7 @@ namespace OpenVic {
return truncate();
}

return ceil<value_type>();
return ceil<int32_t>();
}

OV_SPEED_INLINE constexpr fixed_point_t round() const {
Expand Down
6 changes: 4 additions & 2 deletions tests/src/core/random/WeightedSampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ TEST_CASE("WeightedSampling limits", "[WeightedSampling]") {
const fixed_point_t weights_sum = fixed_point_t::usable_max;
constexpr size_t perfect_divisor = 257; //4294967295 is perfectly divisible by 257
std::array<fixed_point_t, perfect_divisor> weights {};
assert(weights.size() < std::numeric_limits<int32_t>::max());
constexpr uint32_t step_size = max_random_value / weights.size();
weights.fill(weights_sum / weights.size());
weights.fill(weights_sum / static_cast<int32_t>(weights.size()));
for (size_t i = 0; i < weights.size(); ++i) {
CHECK(sample_weighted_index(
i * step_size,
Expand All @@ -33,8 +34,9 @@ TEST_CASE("WeightedSampling weights", "[WeightedSampling]") {
std::array<fixed_point_t, max_length> weights {};

fixed_point_t weights_sum = 0;
assert(weights.size() < std::numeric_limits<int32_t>::max());
for (size_t i = 0; i < weights.size(); ++i) {
const fixed_point_t weight = 1+i;
const fixed_point_t weight = static_cast<int32_t>(1+i);
weights_sum += weight;
weights[i] = weight;
}
Expand Down