Potential bug in strconv.ParseFloat

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.

Hi @christophberger ,
thanks for your reply.

I guess in that case the documentation must be faulty.

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)

Why is this in the float section then ?

This line should indeed be marked as an invalid number, like the ones below it.