RFE: parser and formatter hexfloat support
- Dominant language
- Jsonnet
- Stars
- 7.6k
- Forks
- 475
- PR merge metrics
- No merged PRs in 30d
Description
For a project I'm currently working on, we need our JSON datasets to support bit-precise floating point numbers to manage some tests; we've extended our JSON parser to support C99/C++11-style hexfloats, and we'd like to extend Jsonnet the same way. A hexfloat looks like: `0x1.921fb54p+1` (to represent pi).
I propose to make the following changes:
- Change the lexer and parser to support hexfloats. It's possible that hexfloat parsing could be implemented as part of `std`, but it seems like this probably better lives just in the parser itself -- ergonomically, after all, these are just a different format of literals.
- No change is needed to the formatter's Unparser, since it spits out numbers as they came in from the input.
- Modify `jsonnet_unparse_number` to take a `bool hexfloat` parameter, which controls whether it is willing to output hexfloats. If it is, and a number cannot be represented precisely in five or so digits of decimal, then it preferentially outputs a hexfloat.
- Modify the `vm` to plumb that `hexfloat` parameter through.
- And, finally, modify the `jsonnet eval` tool to take a `hexfloat` command line option. We go through all this plumbing trouble, of course, because hexfloats are not valid real JSON -- but, some floats cannot be represented precisely in JSON, no matter how many digits we include.
I'm working with the NVIDIA legal folks to get a CLA signed on this so I can add these. Does this sound like something that would be accepted upstream if I wrote a PR for it?
Contributor guide
Assessment
This issue has not been assessed yet.