HaxeFoundation / HaxeFoundation/haxe
cpp.Lib.setFloatFormat but for other targets?
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I've talked about this issue plenty on the Discord, but I am frequently running into issues where I need to use ``Haxe.JSON.Stringify``, and will need to maintain float precision for some of the data, but in the process of this, floats will typically lose precision if they trail off too far. I understand that this is just how floating precision works, but in my experience in trying to tackle this problem, I've found that 16 decimals is what I need.
When targeting C++, I can call ``cpp.Lib.setFloatFormat("%.16f")``, and my precision issues are completely solved. However, for targets like HashLink, which I am currently using, I am unable to control this value and the data I'm trying to store as a JSON is effectively useless. I need to maintain this precision as the game I'm working on relies on a deterministic physics engine, and the current level of precision that's being used is different enough to break this.
I would really rather not make my own JSON parser just for this when C++ has a far easier solution to my problem, would greatly appreciate this being looked at and added.
Contributor guide
Research direction
Start by comparing cpp.Lib.setFloatFormat with Haxe.JSON.Stringify and the HashLink target behavior described in the issue. Trace where JSON float formatting is selected for each target, then define how equivalent precision control would be exposed and verify that serialized values preserve the requested precision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, json
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100