diff --git a/CHANGELOG.md b/CHANGELOG.md index 705a66c..2aea7d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [0.7.0] - 2024-02-10 - Update tomlc99 to the latest version +- Parse very large numbers as Infinity ## [0.6.0] - 2023-05-05 diff --git a/ext/tomlib/toml.c b/ext/tomlib/toml.c index e7b878e..4a2f7dc 100644 --- a/ext/tomlib/toml.c +++ b/ext/tomlib/toml.c @@ -2203,7 +2203,7 @@ int toml_rtod_ex(toml_raw_t src, double *ret_, char *buf, int buflen) { } int toml_rtod(toml_raw_t src, double *ret_) { - char buf[100]; + char buf[400]; return toml_rtod_ex(src, ret_, buf, sizeof(buf)); } diff --git a/ext/tomlib/tomlib.c b/ext/tomlib/tomlib.c index fe1c495..b3fe73d 100644 --- a/ext/tomlib/tomlib.c +++ b/ext/tomlib/tomlib.c @@ -187,7 +187,7 @@ static VALUE toml_table_key_to_rb_value(const toml_table_t *table, const char *k datum = toml_double_in(table, key); - if (datum.ok) { + if (datum.ok || datum.u.d == INFINITY || datum.u.d == -INFINITY) { return DBL2NUM(datum.u.d); } diff --git a/spec/examples/parser/valid/spec-very-large-floats.toml b/spec/examples/parser/valid/spec-very-large-floats.toml new file mode 100644 index 0000000..64eaeeb --- /dev/null +++ b/spec/examples/parser/valid/spec-very-large-floats.toml @@ -0,0 +1,4 @@ +ex1 = 1e1000 +ex2 = -1e1000 +ex3 = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0 +ex4 = -9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0 diff --git a/spec/examples/parser/valid/spec-very-large-floats.yaml b/spec/examples/parser/valid/spec-very-large-floats.yaml new file mode 100644 index 0000000..4abae26 --- /dev/null +++ b/spec/examples/parser/valid/spec-very-large-floats.yaml @@ -0,0 +1,4 @@ +ex1: .inf +ex2: -.inf +ex3: .inf +ex4: -.inf