diff --git a/numeric.go b/numeric.go index 3f2dc9ae..72e59b69 100644 --- a/numeric.go +++ b/numeric.go @@ -403,6 +403,10 @@ func (dst *Numeric) toBigInt() (*big.Int, error) { func (src *Numeric) toFloat64() (float64, error) { if src.NaN { return math.NaN(), nil + } else if src.InfinityModifier == Infinity { + return math.Inf(1), nil + } else if src.InfinityModifier == NegativeInfinity { + return math.Inf(-1), nil } buf := make([]byte, 0, 32) diff --git a/numeric_test.go b/numeric_test.go index f14cf960..ecd2d95e 100644 --- a/numeric_test.go +++ b/numeric_test.go @@ -287,6 +287,10 @@ func TestNumericAssignTo(t *testing.T) { {src: &pgtype.Numeric{Int: big.NewInt(1006), Exp: -2, Status: pgtype.Present}, dst: &f64, expected: float64(10.06)}, // https://github.com/jackc/pgtype/issues/27 {src: &pgtype.Numeric{Status: pgtype.Present, NaN: true}, dst: &f64, expected: math.NaN()}, {src: &pgtype.Numeric{Status: pgtype.Present, NaN: true}, dst: &f32, expected: float32(math.NaN())}, + {src: &pgtype.Numeric{Status: pgtype.Present, InfinityModifier: pgtype.Infinity}, dst: &f64, expected: math.Inf(1)}, + {src: &pgtype.Numeric{Status: pgtype.Present, InfinityModifier: pgtype.Infinity}, dst: &f32, expected: float32(math.Inf(1))}, + {src: &pgtype.Numeric{Status: pgtype.Present, InfinityModifier: pgtype.NegativeInfinity}, dst: &f64, expected: math.Inf(-1)}, + {src: &pgtype.Numeric{Status: pgtype.Present, InfinityModifier: pgtype.NegativeInfinity}, dst: &f32, expected: float32(math.Inf(-1))}, } for i, tt := range simpleTests {