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

NaN to json and back #515

Closed
martukas opened this issue Mar 17, 2017 · 2 comments
Closed

NaN to json and back #515

martukas opened this issue Mar 17, 2017 · 2 comments

Comments

@martukas
Copy link

double val = std::numeric_limits::quiet_NaN();
DBG << "val=" << val;
json j = val;
DBG << "j=" << j.dump();
val = j;
DBG << "val=" << val;

goes like this:

val=nan
j=null
terminate called after throwing an instance of 'std::domain_error'
what(): type must be number, but is null

Could this not be behave nicer?

@nlohmann
Copy link
Owner

With the code in the develop branch, this works:

int main()
{
    double val = std::numeric_limits<double>::quiet_NaN();
    std::cout << "val=" << val << std::endl;
    json j = val;
    std::cout << "j=" << j.dump() << std::endl;
    val = j;
    std::cout << "val=" << val << std::endl;
}

output:

val=nan
j=null
val=nan

Note the develop branch is unreleased and is subject to changes until version 3.0.0. This behavior of NaN was only introduced recently.

@nlohmann
Copy link
Owner

@martukas Did you try the develop branch? Could you comment on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants