Support arbitrary precision numbers
Opened this issue · 1 comments
I would like to use picojson in a situation where the numbers are very large, and I use gmp.
I don't expect picojson to support gmp, instead I would like picojson to just provide hooks.
At the moment I have a version of picojson where at the top I have a block of code like:
#ifndef PICOJSON_REPLACE_DOUBLE
typedef double JsonNumber;
inline bool picoJson_isFinite(JsonNumber) { ... }
inline std::string picoJson_DoubleToString(JsonNumber) { ... }
inline double picoJson_StringToDouble(std::string) { ... } // this method can throw
#endif
Basically, providing a configuration point for all the places where doubles are currently manipulated, so a user can easily provide an alternative overload for these methods. Alternatively, these could be spread throughout the code?
I just was wondering if you would be interested in this code before I go to the effort of cleaning it up, or if I should just keep it as local changes.
This could be used to replace the int64_t code (at the cost of changing the interface which is currently being used -- instead we would provide a 'struct number { int64_t i; double d; bool is_double};' class and appropriate overloads).
Thank you for the suggestion. I understand that such need exists and I feel grateful for your proposal.
Use of type traits is the only answer if picojson is going to add support for GMP (or any kind of non-default type to represent numbers). I have created PR #52 that tries to implement a type traits for numbers so that users can use their own type for representing numbers. However the code has not been tested.
It would be great if you could either:
- add a GMP-based number representation using the provided traits interface (as a separate include file)
- or open-source your current work (under the same license terms as kazuho/picojson) so that I could convert it to fit the traits interface
Thank you in advance.