Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get float pointer for value stored as 0 #484

Closed
koemeet opened this issue Mar 6, 2017 · 4 comments
Closed

Cannot get float pointer for value stored as 0 #484

koemeet opened this issue Mar 6, 2017 · 4 comments
Labels
kind: question solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)

Comments

@koemeet
Copy link
Contributor

koemeet commented Mar 6, 2017

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?

@koemeet koemeet changed the title Cannot get float pointer for int storage type Cannot get float pointer for value stored as 0 Mar 6, 2017
@koemeet
Copy link
Contributor Author

koemeet commented Mar 7, 2017

I am using the following as a temporary solution:

/// 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);
	}

    return is_number_float() ? &m_value.number_float : nullptr;
}

@nlohmann nlohmann added kind: question state: help needed the issue needs help to proceed labels Mar 7, 2017
@nlohmann
Copy link
Owner

nlohmann commented 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
Copy link
Contributor

gregmarr commented 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
Copy link
Owner

I think changing the library in this regard is not helpful.

@nlohmann nlohmann added solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope) and removed state: help needed the issue needs help to proceed labels Mar 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: wontfix the issue will not be fixed (either it is impossible or deemed out of scope)
Projects
None yet
Development

No branches or pull requests

3 participants