Comments (1)
I can get the new test case to pass.
diff --git a/fastfloat/parse.go b/fastfloat/parse.go
index b37838d..b8a0bbe 100644
--- a/fastfloat/parse.go
+++ b/fastfloat/parse.go
@@ -500,6 +500,15 @@ func Parse(s string) (float64, error) {
if expMinus {
exp = -exp
}
+ if d != uint64(f) {
+ // TODO comment.
+ // Fall back to standard parsing.
+ f, err := strconv.ParseFloat(s, 64)
+ if err != nil && !math.IsInf(f, 0) {
+ return 0, fmt.Errorf("cannot parse exponent in %q: %s", s, err)
+ }
+ return f, nil
+ }
f *= math.Pow10(int(exp))
if i >= uint(len(s)) {
if minus {
diff --git a/fastfloat/parse_test.go b/fastfloat/parse_test.go
index e4dfe2f..e06912a 100644
--- a/fastfloat/parse_test.go
+++ b/fastfloat/parse_test.go
@@ -445,6 +445,7 @@ func TestParseSuccess(t *testing.T) {
f("-123e456", math.Inf(-1)) // too big exponent
f("1e4", 1e4)
f("-1E-10", -1e-10)
+ f("8.54E-4", 8.54e-4)
// Fractional + exponent part
f("0.123e4", 0.123e4)
However, it does seem to go down the fallback route for some of the other test cases, which is not ideal and perhaps adversely affecting perf.
cc @valyala - would you be able to address this case? Or, let me know if my proposed fix is good enough and I can raise it as a PR. I believe a better option may exist but I'm not seeing it.
So far I've found mulitple apis I use which indeed respond with JSON number values like 8.54E-4
. I would have to use MarshalTo
to then parse it with strconv
to get around it.
from fastjson.
Related Issues (20)
- Provide more context in `Validate()`
- fastjson doesn't iterate over a json
- How to escape json string
- How to decode JSON from []byte? HOT 3
- How to concatenate two []*fastjson.Value arrays to single one and save it to file
- Keep getting error on GetString HOT 1
- sometimes the parsing has error coz json format "invalid" like missing comma
- the very fucking thing is xxx.String() -> ""xxxx""
- support reading json file?
- Marshaling does not agree with json.Encoder
- Parser does not fully validate the JSON HOT 1
- Special characters in the string are incorrectly encoded HOT 3
- Why maintain parser and validate separately?
- pls provide examples and numbers in bytes for the memory usage meaning
- will mutex lock access be supported in future?
- clean way to distinguish between float and int numbers?
- Any way to get the _raw_ bytes from the key? (GetRaw("key"))
- Inconsistent interface of fastjson.GetString( data, "key") and value Get("key").String()
- func s2s use deprecated code in golang 1.20
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 fastjson.