Skip to content

encode: use 64-bit parsing for float32s - #857

Merged
madelynnblue merged 1 commit into
lib:masterfrom
jordanlewis:float32
May 3, 2019
Merged

encode: use 64-bit parsing for float32s#857
madelynnblue merged 1 commit into
lib:masterfrom
jordanlewis:float32

Conversation

@jordanlewis

Copy link
Copy Markdown
Contributor

Previously, float4 values were incorrectly parsed by this library. For
example, a value of 1.2::float4 would be returned to the user as a
float64 of 1.2000000476837158. Now, float4s are parsed correctly,
using the 64-bit-float string parsing facility, and return 1.2 as
expected. Note that this problem only showed up if you used the returned
float64 value from lib/pq directly - casting to a float32 would make the
problem stay hidden - but since lib/pq returns float64, we should make
an effort for that value to be correct anyway.

This was found during investigation here: cockroachdb/cockroach#36811

@jordanlewis

Copy link
Copy Markdown
Contributor Author

@mjibson could you PTAL?

@knz

knz commented May 3, 2019

Copy link
Copy Markdown

LGTM

Comment thread encode.go Outdated
Previously, float4 values were incorrectly parsed by this library. For
example, a value of `1.2::float4` would be returned to the user as a
float64 of `1.2000000476837158`. Now, float4s are parsed correctly,
using the 64-bit-float string parsing facility, and return 1.2 as
expected. Note that this problem only showed up if you used the returned
float64 value from lib/pq directly - casting to a float32 would make the
problem stay hidden - but since lib/pq returns float64, we should make
an effort for that value to be correct anyway.
@madelynnblue
madelynnblue merged commit bc6a3c0 into lib:master May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants