Merge pull request #544 from heedson/fix-numeric-negative-0
pgtype: Fix -0 for numeric types
This commit is contained in:
+1
-1
@@ -321,7 +321,7 @@ func parseNumericString(str string) (n *big.Int, exp int32, err error) {
|
|||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
exp = int32(-len(parts[1]))
|
exp = int32(-len(parts[1]))
|
||||||
} else {
|
} else {
|
||||||
for len(digits) > 1 && digits[len(digits)-1] == '0' {
|
for len(digits) > 1 && digits[len(digits)-1] == '0' && digits[len(digits)-2] != '-' {
|
||||||
digits = digits[:len(digits)-1]
|
digits = digits[:len(digits)-1]
|
||||||
exp++
|
exp++
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pgtype_test
|
package pgtype_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -65,6 +66,13 @@ func TestNumericArraySet(t *testing.T) {
|
|||||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||||
Status: pgtype.Present},
|
Status: pgtype.Present},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: []float32{float32(math.Copysign(0, -1))},
|
||||||
|
result: pgtype.NumericArray{
|
||||||
|
Elements: []pgtype.Numeric{{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||||
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||||
|
Status: pgtype.Present},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
source: []float64{1},
|
source: []float64{1},
|
||||||
result: pgtype.NumericArray{
|
result: pgtype.NumericArray{
|
||||||
@@ -72,6 +80,13 @@ func TestNumericArraySet(t *testing.T) {
|
|||||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||||
Status: pgtype.Present},
|
Status: pgtype.Present},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: []float64{math.Copysign(0, -1)},
|
||||||
|
result: pgtype.NumericArray{
|
||||||
|
Elements: []pgtype.Numeric{{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||||
|
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 1}},
|
||||||
|
Status: pgtype.Present},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
source: (([]float32)(nil)),
|
source: (([]float32)(nil)),
|
||||||
result: pgtype.NumericArray{Status: pgtype.Null},
|
result: pgtype.NumericArray{Status: pgtype.Null},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pgtype_test
|
package pgtype_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -188,7 +189,9 @@ func TestNumericSet(t *testing.T) {
|
|||||||
result *pgtype.Numeric
|
result *pgtype.Numeric
|
||||||
}{
|
}{
|
||||||
{source: float32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
{source: float32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||||
|
{source: float32(math.Copysign(0, -1)), result: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||||
{source: float64(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
{source: float64(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||||
|
{source: float64(math.Copysign(0, -1)), result: &pgtype.Numeric{Int: big.NewInt(0), Status: pgtype.Present}},
|
||||||
{source: int8(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
{source: int8(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||||
{source: int16(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
{source: int16(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||||
{source: int32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
{source: int32(1), result: &pgtype.Numeric{Int: big.NewInt(1), Status: pgtype.Present}},
|
||||||
|
|||||||
Reference in New Issue
Block a user