forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow constant values of infininitesimal non-zero floating points (
gnolang#1185) Added a unit test and an integration test trying to reproduce gnolang#1150 Avoid unhandled errors. - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [x] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). --------- Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com> Co-authored-by: Morgan Bazalgette <morgan@morganbaz.com>
- Loading branch information
Showing
4 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gnolang | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/cockroachdb/apd" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConvertUntypedBigdecToFloat(t *testing.T) { | ||
dst := &TypedValue{} | ||
|
||
dec, err := apd.New(-math.MaxInt64, -4).SetFloat64(math.SmallestNonzeroFloat64 / 2) | ||
require.NoError(t, err) | ||
bd := BigdecValue{ | ||
V: dec, | ||
} | ||
|
||
typ := Float64Type | ||
|
||
ConvertUntypedBigdecTo(dst, bd, typ) | ||
|
||
require.Equal(t, float64(0), dst.GetFloat64()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
const ( | ||
SmallestNonzeroFloat64 = 0x1p-1022 * 0x1p-52 // 4.9406564584124654417656879286822137236505980e-324 | ||
DividedByTwo = SmallestNonzeroFloat64 / 2 | ||
) | ||
|
||
func main() { | ||
println(DividedByTwo) | ||
} | ||
|
||
// Output: | ||
// 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
const ( | ||
SmallestNonzeroFloat32 = 0x1p-126 * 0x1p-23 // 1.401298464324817070923729583289916131280e-45 | ||
DividedByTwo = SmallestNonzeroFloat32 / 2 | ||
) | ||
|
||
func main() { | ||
var i float32 | ||
i = DividedByTwo | ||
println(i) | ||
} | ||
|
||
// Output: | ||
// 0 |