Commit 9c20112d authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

gui: fix plot output for integer8/32/64

parent 11af0c74
......@@ -85,7 +85,7 @@ observation_output_observe(const irt::observer& obs,
return;
auto* output = reinterpret_cast<observation_output*>(obs.user_data);
const auto value = static_cast<float>(msg.to_real_64(0));
const auto value = static_cast<float>(msg.cast_to_real_64(0));
if (output->observation_type == observation_output::type::plot ||
output->observation_type == observation_output::type::both) {
......
......@@ -684,6 +684,28 @@ struct message
return real_64[i];
}
template<typename T>
constexpr double cast_to_real_64(T i) const
{
if constexpr (std::is_signed_v<T>)
assert(i >= 0);
switch (type) {
case value_type::integer_8:
return static_cast<double>(to_integer_8(i));
case value_type::integer_32:
return static_cast<double>(to_integer_32(i));
case value_type::integer_64:
return static_cast<double>(to_integer_64(i));
case value_type::real_32:
return static_cast<double>(to_real_32(i));
case value_type::real_64:
return static_cast<double>(to_real_64(i));
}
return 0.0;
}
};
/*****************************************************************************
......@@ -3254,12 +3276,12 @@ struct counter
model_id id;
input_port_id x[1];
time sigma;
long unsigned number;
i64 number;
status initialize(
data_array<message, message_id>& /*init_messages*/) noexcept
{
number = 0ul;
number = { 0 };
sigma = time_domain<time>::infinity;
return status::success;
......@@ -3275,16 +3297,11 @@ struct counter
diff += std::distance(std::begin(port->messages),
std::end(port->messages));
number += static_cast<long unsigned>(diff);
number += static_cast<i64>(diff);
return status::success;
}
status internal(time /*t*/) noexcept
{
return status::success;
}
message observation(time /*t*/) const noexcept
{
return message(number);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment