miloyip/rapidjson — pull request #137 by miloyip (2014-09-06 03:02:57+00:00)
Title: Parse JSON number to double in full-precision.

Use `kParseFullPrecision` to turn on this option in compile-time. The implementation of new option should have no performance impact if the flag is not used.

## Implementation details

The full-precision path tries to use fast-path if possible. If the criteria of fast-path cannot be met, it falls back to use `strtod()` to convert string.

Note that the parser still verify the JSON syntax of number as in normal-precision path.

To fulfill the above requirement, the parser needs to backup the correctly parsed characters from stream (as some streams cannot read back). A helper template class `GenericReader::NumberStream` is designed for this. If full-precision is set, then backup is required, and a specialized `NumberStream` will backup the characters during `NumberStream::Take()` into the `GenericReader::stack_`. That `stack_` was previously used only for storing the decoded characters in `ParseString()`.

## Unit test

Added random numbers to test more cases for integer types and `double`.

This experimental results show that full precision generate exact representation (no error), while normal precision parsing has maximum error of 3 ULP.

Denormal numbers () are not tested as it varies among platforms. Implementations of strtod()` in standard libraries may also simply flush denormal to zero.

Fix #120