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

Source data doesn't match test data #72

Closed
g-andrade opened this issue Nov 4, 2019 · 1 comment · Fixed by #73
Closed

Source data doesn't match test data #72

g-andrade opened this issue Nov 4, 2019 · 1 comment · Fixed by #73

Comments

@g-andrade
Copy link
Contributor

g-andrade commented Nov 4, 2019

In a specific case under GeoIP2-Static-IP-Score-Test.json, recently modified in order to use floating point values, the JSON value 0.3 is corrupted when generating MMDB test data.

The problem is, 0.3 has no precise representation in binary floating point - its closest representable value is 2.99999999999999988898e-01. But in this case, it's read as 0.30000000000000004 instead, which is the value to be found within GeoIP2-Static-IP-Score-Test.mmdb.

I boiled the issue down to what's (presumably) a bug in the Cpanel::JSON::XS library, which is used to decode the JSON sources.

Here's a small perl script that reproduces the issue:

use Cpanel::JSON::XS qw( decode_json );

my $literal_float = 0.3;
my $json_object = decode_json('{"value": 0.3}');
my $json_float = $json_object->{value};

my $difference = $literal_float - $json_float;
print "$difference\n"

It outputs -5.55111512312578e-17. Mind. Blowing.

@oschwald
Copy link
Member

oschwald commented Nov 4, 2019

Thanks for opening this and reporting it upstream! It should be fixed now.

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

Successfully merging a pull request may close this issue.

2 participants