Comments (6)
I would be ok with a different function, but TrimAndCut
also ensures that the given buffer doesn't have too many digits.
This happens in two steps:
- the trailing '0' digits are removed (while updating the exponent), and
- the digits are "cut" off if there are too many.
Sounds like a very special case where you are sure that you will never need this.
It might be more interesting to add a shortcut to the Strtod
function that checks rapidly whether the buffer starts with non-'0' and ends with non-'0', and is short enough.
Wdyt?
from double-conversion.
Our parsing front-end also checks the number of digits before copying them (we'd do zero-copy, but that's not generally possible due to the decimal point, and I haven't been bother to try something else for using the input's buffer in-place). We really just need the back-end conversion without any checks at all because that seems to be the most efficient way of bolting your Strtod()
to our library.
Btw, it was mostly thanks to double-conversion that our JSON library achieved 100% conformance in the nativejson-benchmarks, if you happen to know that. Integration was a bit of an effort since we are currently header-only, and had to make the parts of double-conversion that we need header-only, too, but definitely worth it.
(The plain grammar accepts any number of digits, but the semantic actions that prepare the character array with the digits, and the int
with the exponent, do all size checks, and strip trailing zeros before copying them; as mentioned the grammar itself doesn't allow leading zeros.)
https://github.com/taocpp/json/blob/master/include/tao/json/internal/grammar.hpp
https://github.com/taocpp/json/blob/master/include/tao/json/internal/action.hpp
https://github.com/taocpp/json/blob/master/include/tao/json/internal/number_state.hpp
https://github.com/taocpp/json/blob/master/include/tao/json/external/double.hpp
from double-conversion.
Having a separate function is fine then.
I think I would call it StrtodTrimmed
. You can refer in the documentation to TrimAndCut
, and mention that most users probably don't need it (and should use Strtod
instead).
I don't think there is a need to add StrtofTrimmed
(unless you need it) already now. Can easily be added at a later point.
For good measure I would add an ASSERT
to check that the buffer that is given to StrtodTrimmed
is the same as the one after TrimAndCut
.
I don't think you need to add lots of tests. However, I would test the corner cases, like the longest possible numbers, 0, ...
from double-conversion.
We don't need it for floats, and StrtodTrimmed()
is fine.
And: You mean the assert should copy the input, pump it through TrimAndCut()
, and then assert that neither the data nor the exponent changed?
from double-conversion.
Yes. I would try to add such an assert.
It's not strictly necessary, but nicely shows the expectations of the function (and potentially catches bugs).
from double-conversion.
PR created, we can continue discussing there.
from double-conversion.
Related Issues (20)
- How to "install" built libraries on Windows HOT 4
- make-ing library on Windows 10 HOT 11
- Maximum string length DoubleToStringConverter::EcmaScriptConverter() ToShortest? 26 chars? HOT 8
- kMaxFixedDigitsAfterPoint should be increased from 60 to 100 HOT 2
- StringToDoubleConverter::StringToDouble slower than dtoa HOT 3
- `StringToDoubleConverter::StringTo<FloatingPoint>` member function templates HOT 3
- Add generic (template) methods for `to_string` (float or double). HOT 2
- New tag/version since 2019? HOT 2
- [bug] ieee.h: Wrong QuietNaN bit check on mips* architectures HOT 1
- Kindly add installation of Windows debugger files (pdb)? HOT 5
- FastFixedDtoa incorrect rounding. HOT 1
- Fix -Wzero-as-null-pointer-constant warnings HOT 12
- Tag a v3.2.1 release? HOT 2
- Various warnings compiling with visual studio HOT 1
- Insecure API when using in React Native iOS app HOT 1
- Set GitHub Workflow permissions to read only HOT 1
- [vulnerability] CVE issues HOT 4
- Hash Pin Github Owned Actions HOT 3
- Enable OpenSSF Scorecard Action and Badge HOT 1
- question: does abseil-cpp cover double-conversion functionality HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from double-conversion.