mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Add infinity support for Numeric AssignTo
This commit is contained in:
parent
e0f9fc5212
commit
001b3166b9
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user