Scarjit
(Ferdinand Linnenberg)
October 10, 2022, 9:46am
1
While checking an microservice of our, i noticed that it fails to accept strings like these:
“0x15e-2”.
The service internally uses strconv.ParseFloat, and the string above is taken straight from the go ref (The Go Programming Language Specification - The Go Programming Language ).
The error is:
strconv.ParseFloat: parsing "0x15e-2": invalid syntax
A minimal example to reproduce the error:
Is this an error in the go spec or an error inside ParseFloat ?
Regards
Ferdinand Linnenberg
Hi @Scarjit ,
I think the error occurs because the exponent for hex numbers must start with a “p”. The letter “e” is ambiguous as it is also a valid hexadecimal digit.
Scarjit
(Ferdinand Linnenberg)
October 10, 2022, 12:44pm
4
Hi @christophberger ,
thanks for your reply.
I guess in that case the documentation must be faulty.
skillian
(Sean Killian)
October 10, 2022, 7:44pm
5
Where are you seeing that? The only inatance of that number that I see is on the line that says it is interpretted as integer subtraction:
0x15e-2 // == 0x15e - 2 (integer subtraction)
Scarjit
(Ferdinand Linnenberg)
October 10, 2022, 8:33pm
6
Why is this in the float section then ?
This line should indeed be marked as an invalid number, like the ones below it.
system
(system)
Closed
January 8, 2023, 8:44pm
8
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.