Skip to content

Commit

Permalink
Change test to use constants and remove panic
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
  • Loading branch information
ajnavarro committed Oct 4, 2023
1 parent 8e943c6 commit 019c00e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,7 @@ func ConvertUntypedBigdecTo(dst *TypedValue, bv BigdecValue, t Type) {
if err != nil {
panic(fmt.Errorf("cannot convert untyped bigdec to float64: %w", err))

Check warning on line 1262 in gnovm/pkg/gnolang/values_conversions.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/values_conversions.go#L1262

Added line #L1262 was not covered by tests
}
if f64 == 0 && !bd.IsZero() {
panic("cannot convert untyped bigdec to float64 -- too close to zero")
} else if math.IsInf(f64, 0) {
if math.IsInf(f64, 0) {
panic("cannot convert untyped bigdec to float64 -- too close to +-Inf")
}
dst.SetFloat64(f64)
Expand Down
9 changes: 6 additions & 3 deletions gnovm/tests/testdata/TestMemPackage/success/float_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package test

import "testing"

func TestSmallestFloat(t *testing.T) {
SmallestNonzeroFloat64 := 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324
DividedByTwo := SmallestNonzeroFloat64 / 2
const (
SmallestNonzeroFloat64 = 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324
DividedByTwo = SmallestNonzeroFloat64 / 2
)


func TestSmallestFloat(t *testing.T) {
println(DividedByTwo)
}

0 comments on commit 019c00e

Please sign in to comment.