Skip to content

Commit

Permalink
work around #1462
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Jan 8, 2024
1 parent 5975c13 commit 9ce2935
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions gnovm/stdlibs/strconv/atof.gno
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (d *decimal) floatBits(flt *floatInfo) (b uint64, overflow bool) {
exp += n
}

if exp-flt.bias >= 1<<flt.expbits-1 {
if exp-flt.bias >= int(1)<<flt.expbits-1 {
goto overflow
}

Expand All @@ -379,32 +379,32 @@ func (d *decimal) floatBits(flt *floatInfo) (b uint64, overflow bool) {
mant = d.RoundedInteger()

// Rounding might have added a bit; shift down.
if mant == 2<<flt.mantbits {
if mant == uint64(2)<<flt.mantbits {
mant >>= 1
exp++
if exp-flt.bias >= 1<<flt.expbits-1 {
if exp-flt.bias >= int(1)<<flt.expbits-1 {
goto overflow
}
}

// Denormalized?
if mant&(1<<flt.mantbits) == 0 {
if mant&(uint64(1)<<flt.mantbits) == 0 {
exp = flt.bias
}
goto out

overflow:
// ±Inf
mant = 0
exp = 1<<flt.expbits - 1 + flt.bias
exp = int(1)<<flt.expbits - 1 + flt.bias
overflow = true

out:
// Assemble bits.
bits := mant & (uint64(1)<<flt.mantbits - 1)
bits |= uint64((exp-flt.bias)&(1<<flt.expbits-1)) << flt.mantbits
bits |= uint64((exp-flt.bias)&(int(1)<<flt.expbits-1)) << flt.mantbits
if d.neg {
bits |= 1 << flt.mantbits << flt.expbits
bits |= uint64(1) << flt.mantbits << flt.expbits
}
return bits, overflow
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func atof32exact(mantissa uint64, exp int, neg bool) (f float32, ok bool) {
// The string s has already been parsed into a mantissa, exponent, and sign (neg==true for negative).
// If trunc is true, trailing non-zero bits have been omitted from the mantissa.
func atofHex(s string, flt *floatInfo, mantissa uint64, exp int, neg, trunc bool) (float64, error) {
maxExp := 1<<flt.expbits + flt.bias - 2
maxExp := int(1)<<flt.expbits + flt.bias - 2
minExp := flt.bias + 1
exp += int(flt.mantbits) // mantissa now implicitly divided by 2^mantbits.

Expand Down Expand Up @@ -534,7 +534,7 @@ func atofHex(s string, flt *floatInfo, mantissa uint64, exp int, neg, trunc bool
exp += 2
if round == 3 {
mantissa++
if mantissa == 1<<(1+flt.mantbits) {
if mantissa == uint64(1)<<(1+flt.mantbits) {
mantissa >>= 1
exp++
}
Expand All @@ -545,15 +545,15 @@ func atofHex(s string, flt *floatInfo, mantissa uint64, exp int, neg, trunc bool
}
var err error
if exp > maxExp { // infinity and range error
mantissa = 1 << flt.mantbits
mantissa = uint64(1) << flt.mantbits
exp = maxExp + 1
err = rangeError(fnParseFloat, s)
}

bits := mantissa & (1<<flt.mantbits - 1)
bits |= uint64((exp-flt.bias)&(1<<flt.expbits-1)) << flt.mantbits
bits := mantissa & (uint64(1)<<flt.mantbits - 1)
bits |= uint64((exp-flt.bias)&(int(1)<<flt.expbits-1)) << flt.mantbits
if neg {
bits |= 1 << flt.mantbits << flt.expbits
bits |= uint64(1) << flt.mantbits << flt.expbits
}
if flt == &float32info {
return float64(math.Float32frombits(uint32(bits))), err
Expand Down
2 changes: 1 addition & 1 deletion gnovm/stdlibs/strconv/atof_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func testAtof(t *testing.T, opt bool) {
outs := FormatFloat(out, 'g', -1, 64)
if outs != test.out || !errEqual(err, test.err) {
t.Errorf("ParseFloat(%v, 64) = %v, %v want %v, %v",
test.in, out, printError(err), test.out, printError(err))
test.in, out, printError(err), test.out, printError(test.err))
}

if float64(float32(out)) == out {
Expand Down
10 changes: 5 additions & 5 deletions gnovm/stdlibs/strconv/ftoa.gno
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func genericFtoa(dst []byte, val float64, fmt byte, prec, bitSize int) []byte {
mant := bits & (uint64(1)<<flt.mantbits - 1)

switch exp {
case 1<<flt.expbits - 1:
case int(1)<<flt.expbits - 1:
// Inf, NaN
var s string
switch {
Expand Down Expand Up @@ -275,7 +275,7 @@ func roundShortest(d *decimal, mant uint64, exp int, flt *floatInfo) {
// Our lower bound is halfway between, mantlo*2+1 << explo-mantbits-1.
var mantlo uint64
var explo int
if mant > 1<<flt.mantbits || exp == minexp {
if mant > uint64(1)<<flt.mantbits || exp == minexp {
mantlo = mant - 1
explo = exp
} else {
Expand Down Expand Up @@ -494,7 +494,7 @@ func fmtX(dst []byte, prec int, fmt byte, neg bool, mant uint64, exp int, flt *f

// Shift digits so leading 1 (if any) is at bit 1<<60.
mant <<= 60 - flt.mantbits
for mant != 0 && mant&(1<<60) == 0 {
for mant != 0 && mant&(uint64(1)<<60) == 0 {
mant <<= 1
exp--
}
Expand All @@ -504,11 +504,11 @@ func fmtX(dst []byte, prec int, fmt byte, neg bool, mant uint64, exp int, flt *f
shift := uint(prec * 4)
extra := (mant << shift) & (1<<60 - 1)
mant >>= 60 - shift
if extra|(mant&1) > 1<<59 {
if extra|(mant&1) > uint64(1)<<59 {
mant++
}
mant <<= 60 - shift
if mant&(1<<61) != 0 {
if mant&(uint64(1)<<61) != 0 {
// Wrapped around.
mant >>= 1
exp++
Expand Down

0 comments on commit 9ce2935

Please sign in to comment.