You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot get float pointer for value stored as 0 #484
I am using a web service which doesn't return a floating point all the time. For example, 0 is used to represent 0.0. Because this library needs 0.0 in order to parse it as a float I am having some issues with it. Right now I am unable to get a proper float pointer, simply because the number_float storage is not set.
How would I approach this, since the webservice cannot be changed in order to output 0 as 0.0. I am using lots data that has this, so it would be nice if there was a good solution for this issue.
Any ideas? 😄
Maybe it is a good idea to always store ints and float along side each other?
/// get a pointer to the value (floating-point number)number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept
{
if (is_number_integer())
{
m_type = value_t::number_float;
m_value.number_float = static_cast<float>(m_value.number_integer);
}
returnis_number_float() ? &m_value.number_float : nullptr;
}
I understand your problem, but don't know a solution either. Your fix is pragmatic, but I think it's counter-intuitive to change a type with a getter. Maybe someone else has a better idea?
I'd say this would be a reasonable thing for the library client to do, but not for the library itself to do. If the client knows that it needs a float there, then it's perfectly reasonable for the client to make it a float.
Activity
[-]Cannot get float pointer for int storage type[/-][+]Cannot get float pointer for value stored as `0`[/+]koemeet commentedon Mar 7, 2017
I am using the following as a temporary solution:
nlohmann commentedon Mar 7, 2017
I understand your problem, but don't know a solution either. Your fix is pragmatic, but I think it's counter-intuitive to change a type with a getter. Maybe someone else has a better idea?
gregmarr commentedon Mar 7, 2017
I'd say this would be a reasonable thing for the library client to do, but not for the library itself to do. If the client knows that it needs a float there, then it's perfectly reasonable for the client to make it a float.
nlohmann commentedon Mar 11, 2017
I think changing the library in this regard is not helpful.