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

json conversion of some float64 values seems less precise than expected #23

Open
spoonincode opened this issue Dec 2, 2023 · 0 comments
Labels

Comments

@spoonincode
Copy link
Member

Consider the following which uses the fpconv_dtoa() function as used by abieos' bin->json conversion,

int main() {
	double x = 151115727451828646838272.0;
	std::cout << std::to_string(x) << std::endl;

	char buf[26] = {};
        fpconv_dtoa(x, buf);
	std::cout << buf << std::endl;
	return 0;
}

The output is,

151115727451828646838272.000000
151115727451828650000000

This value is 2^77 and should be perfectly representable in a double -- and std::to_string() clearly shows it as being so. But when fpconv_dtoa() prints it some precision is lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

1 participant