strconv: ParseFloat
silently assumes bitSize=64 for any value that is not 32
#53868
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I called
strconv.ParseFloat
withbitSize=10
. It succeeded.What did you expect to see?
I expected it to fail, as the documentation says it only accepts bitSize=32 and bitSize=64.
What did you see instead?
It didn't fail, but parsed my number.
Why is this an issue
strconv.ParseFloat
silently assumesbitSize=64
for anybitSize
value that is not 32. This means that changing a call fromstrconv.ParseFloat("1.1", 16)
tostrconv.ParseFloat("1.1", 32)
actually decreases the precision instead of increasing it.In my particular case, I made a similar change (suggested by a linter, because honestly, I didn't know about bitSize limitation), and it resulted in a flaky test because of the precision decrease.
Further thoughts
I am not brave enough to open a PR returning an error when
strconv.ParseFloat()
is called with bitSize values that are not 32/64, as I feel that woud break the internet at this point, however I do think that the function should either comply with it's comment, fail, or at least have this behavior documented.The text was updated successfully, but these errors were encountered: