mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-15 20:40:43 +08:00
Updated AdaptType function in utils to use big float and int64 for number coversions.
Updated setget and setget_test to account for new number formatting change.
This commit is contained in:
@@ -9,10 +9,10 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/resp"
|
||||
@@ -103,14 +103,15 @@ func IsInteger(n float64) bool {
|
||||
|
||||
func AdaptType(s string) interface{} {
|
||||
// Adapt the type of the parameter to string, float64 or int
|
||||
n, err := strconv.ParseFloat(s, 32)
|
||||
n, _, err := big.ParseFloat(s, 10, 256, big.RoundingMode(big.Exact))
|
||||
|
||||
if err != nil {
|
||||
return s
|
||||
}
|
||||
|
||||
if IsInteger(n) {
|
||||
return int(n)
|
||||
if n.IsInt() {
|
||||
i, _ := n.Int64()
|
||||
return i
|
||||
}
|
||||
|
||||
return n
|
||||
|
Reference in New Issue
Block a user