mirror of https://github.com/jackc/pgx.git
Rename IsNaN to NaN
parent
ee66a98ace
commit
7bcd9fbdaf
16
numeric.go
16
numeric.go
|
@ -52,7 +52,7 @@ type Numeric struct {
|
|||
Int *big.Int
|
||||
Exp int32
|
||||
Status Status
|
||||
IsNaN bool
|
||||
NaN bool
|
||||
}
|
||||
|
||||
func (dst *Numeric) Set(src interface{}) error {
|
||||
|
@ -71,7 +71,7 @@ func (dst *Numeric) Set(src interface{}) error {
|
|||
switch value := src.(type) {
|
||||
case float32:
|
||||
if math.IsNaN(float64(value)) {
|
||||
*dst = Numeric{Status: Present, IsNaN: true}
|
||||
*dst = Numeric{Status: Present, NaN: true}
|
||||
return nil
|
||||
}
|
||||
num, exp, err := parseNumericString(strconv.FormatFloat(float64(value), 'f', -1, 64))
|
||||
|
@ -81,7 +81,7 @@ func (dst *Numeric) Set(src interface{}) error {
|
|||
*dst = Numeric{Int: num, Exp: exp, Status: Present}
|
||||
case float64:
|
||||
if math.IsNaN(value) {
|
||||
*dst = Numeric{Status: Present, IsNaN: true}
|
||||
*dst = Numeric{Status: Present, NaN: true}
|
||||
return nil
|
||||
}
|
||||
num, exp, err := parseNumericString(strconv.FormatFloat(value, 'f', -1, 64))
|
||||
|
@ -305,7 +305,7 @@ func (dst *Numeric) toBigInt() (*big.Int, error) {
|
|||
}
|
||||
|
||||
func (src *Numeric) toFloat64() (float64, error) {
|
||||
if src.IsNaN {
|
||||
if src.NaN {
|
||||
return math.NaN(), nil
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ func (dst *Numeric) DecodeText(ci *ConnInfo, src []byte) error {
|
|||
}
|
||||
|
||||
if string(src) == "'NaN'" { // includes single quotes, see EncodeText for details.
|
||||
*dst = Numeric{Status: Present, IsNaN: true}
|
||||
*dst = Numeric{Status: Present, NaN: true}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error {
|
|||
rp += 2
|
||||
|
||||
if sign == pgNumericNaNSign {
|
||||
*dst = Numeric{Status: Present, IsNaN: true}
|
||||
*dst = Numeric{Status: Present, NaN: true}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -494,7 +494,7 @@ func (src Numeric) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
|||
return nil, errUndefined
|
||||
}
|
||||
|
||||
if src.IsNaN {
|
||||
if src.NaN {
|
||||
// encode as 'NaN' including single quotes,
|
||||
// "When writing this value [NaN] as a constant in an SQL command,
|
||||
// you must put quotes around it, for example UPDATE table SET x = 'NaN'"
|
||||
|
@ -517,7 +517,7 @@ func (src Numeric) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
|
|||
return nil, errUndefined
|
||||
}
|
||||
|
||||
if src.IsNaN {
|
||||
if src.NaN {
|
||||
buf = pgio.AppendUint64(buf, pgNumericNaN)
|
||||
return buf, nil
|
||||
}
|
||||
|
|
|
@ -210,8 +210,8 @@ func TestNumericSet(t *testing.T) {
|
|||
{source: float64(1234), result: &pgtype.Numeric{Int: big.NewInt(1234), Exp: 0, Status: pgtype.Present}},
|
||||
{source: float64(12345678900), result: &pgtype.Numeric{Int: big.NewInt(123456789), Exp: 2, Status: pgtype.Present}},
|
||||
{source: float64(12345.678901), result: &pgtype.Numeric{Int: big.NewInt(12345678901), Exp: -6, Status: pgtype.Present}},
|
||||
{source: math.NaN(), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, IsNaN: true}},
|
||||
{source: float32(math.NaN()), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, IsNaN: true}},
|
||||
{source: math.NaN(), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, NaN: true}},
|
||||
{source: float32(math.NaN()), result: &pgtype.Numeric{Int: nil, Exp: 0, Status: pgtype.Present, NaN: true}},
|
||||
}
|
||||
|
||||
for i, tt := range successfulTests {
|
||||
|
@ -269,8 +269,8 @@ func TestNumericAssignTo(t *testing.T) {
|
|||
{src: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Null}, dst: &pi8, expected: ((*int8)(nil))},
|
||||
{src: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Null}, dst: &_pi8, expected: ((*_int8)(nil))},
|
||||
{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, IsNaN: true}, dst: &f64, expected: math.NaN()},
|
||||
{src: &pgtype.Numeric{Status: pgtype.Present, IsNaN: true}, dst: &f32, expected: float32(math.NaN())},
|
||||
{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())},
|
||||
}
|
||||
|
||||
for i, tt := range simpleTests {
|
||||
|
|
Loading…
Reference in New Issue