1
0
Fork 0
forked from forgejo/forgejo

update mssql drive to last working version 20180314172330-6a30f4e59a44 (#7306)

This commit is contained in:
Antoine GIRARD 2019-06-30 05:28:17 +02:00 committed by Lunny Xiao
parent aeb8f7aad8
commit 1e46eedce7
46 changed files with 3158 additions and 491 deletions

View file

@ -32,7 +32,13 @@ func (d Decimal) ToFloat64() float64 {
return val
}
const autoScale = 100
func Float64ToDecimal(f float64) (Decimal, error) {
return Float64ToDecimalScale(f, autoScale)
}
func Float64ToDecimalScale(f float64, scale uint8) (Decimal, error) {
var dec Decimal
if math.IsNaN(f) {
return dec, errors.New("NaN")
@ -49,10 +55,10 @@ func Float64ToDecimal(f float64) (Decimal, error) {
}
dec.prec = 20
var integer float64
for dec.scale = 0; dec.scale <= 20; dec.scale++ {
for dec.scale = 0; dec.scale <= scale; dec.scale++ {
integer = f * scaletblflt64[dec.scale]
_, frac := math.Modf(integer)
if frac == 0 {
if frac == 0 && scale == autoScale {
break
}
}
@ -73,7 +79,7 @@ func init() {
}
}
func (d Decimal) Bytes() []byte {
func (d Decimal) BigInt() big.Int {
bytes := make([]byte, 16)
binary.BigEndian.PutUint32(bytes[0:4], d.integer[3])
binary.BigEndian.PutUint32(bytes[4:8], d.integer[2])
@ -84,9 +90,19 @@ func (d Decimal) Bytes() []byte {
if !d.positive {
x.Neg(&x)
}
return x
}
func (d Decimal) Bytes() []byte {
x := d.BigInt()
return scaleBytes(x.String(), d.scale)
}
func (d Decimal) UnscaledBytes() []byte {
x := d.BigInt()
return x.Bytes()
}
func scaleBytes(s string, scale uint8) []byte {
z := make([]byte, 0, len(s)+1)
if s[0] == '-' || s[0] == '+' {