JSON emitting: improve handling of nan, inf and some floats#574
JSON emitting: improve handling of nan, inf and some floats#574
Conversation
|
@davidrudlstorfer @captain-yoshi @sebproell Tagging you here because of #535 and #312 . Please take a look at this PR; IMO it addresses the problems discussed in those issues. As I said above (and you can verify in the tests added in this PR), Other than that, the proposed JSON strings |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #574 +/- ##
==========================================
- Coverage 97.61% 97.57% -0.04%
==========================================
Files 46 46
Lines 13651 13677 +26
==========================================
+ Hits 13326 13346 +20
- Misses 325 331 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@biojppm thanks for the nice fix and also big thanks for the tag. Nice that this is now working as expected :) (@gilrrei now we can revert 4C-multiphysics/fourcipp#78 and 4C-multiphysics/fourcipp#85) |
For example, the tree
```yaml
{
inf: [inf, infinity, .inf, .Inf, .INF, -inf, -infinity, -.inf, -.Inf, -.INF],
nan: [nan, .nan, .NaN, .NAN],
dot: [.1, 1., .2e2, 10., -.2, -2.],
zero: [10, 01],
normal: [0.1, 0.2e3, 4.e5],
}
```
is now emitted to JSON as:
```json
{
".inf": [".inf",".inf",".inf",".inf","-.inf","-.inf","-.inf","-.inf","-.inf","-.inf"],
".nan": [".nan",".nan",".nan",".nan"],
"dot": [0.1,1.0,0.2e2,10.0,-0.2,-2.0],
"zero": [10,"01"],
"normal": [0.1,0.2e3,4.e5]
}
```
Previously, some inf and nan cases were emitted without quotes; now they are all emitted with the fixed strings `.nan` and `.inf`, which helps in cases where the JSON may be loaded in JavaScript. Note also the added zeroes for some floats, eg `.1` or `-2.` turning into `0.1` and `-2.0`.
I tried using "8e888" for int as suggested in #312 but this value cannot be parsed by to_chars() (see proof in added tests), which prevents roundtrip equivalence. So I opted for a sensible `".inf"` string for all inf cases.
a33f75e to
e721250
Compare
For example, the tree
is now emitted to JSON as:
{ "inf": [".inf",".inf",".inf",".inf","-.inf","-.inf","-.inf","-.inf"], "nan": [".nan",".nan",".nan",".nan"], "dot": [0.1,1.0,0.2e2,10.0,-0.2,-2.0], "zero": [10,"01"], "normal": [0.1,0.2e3,4.e5] }Previously, some inf and nan cases were emitted without quotes. Note also the added zeroes for some floats, eg
.1or-2., which turn into0.1and-2.0in JSON.I tried using "8e888" for inf as suggested in #312 but this value cannot be parsed by to_chars() (see proof in added tests), which prevents roundtrip equivalence. So I opted for a sensible
".inf"string for all inf cases.Fixes #312
Fixes #535