Skip to content

Commit

Permalink
Merge branch 'gnolang:master' into feature/block-timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s authored Mar 28, 2023
2 parents 588e7dd + 60eeb9f commit 12a5441
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkgs/gnolang/op_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (m *Machine) doOpEval() {
m.PopExpr()
switch x.Kind {
case INT:
x.Value = strings.ReplaceAll(x.Value, "_", "")
// temporary optimization
bi := big.NewInt(0)
// TODO optimize.
Expand Down Expand Up @@ -76,6 +77,8 @@ func (m *Machine) doOpEval() {
V: BigintValue{V: bi},
})
case FLOAT:
x.Value = strings.ReplaceAll(x.Value, "_", "")

if matched, _ := regexp.MatchString(`^[0-9\.]+([eE][\-\+]?[0-9]+)?$`, x.Value); matched {
value := x.Value
bd, c, err := apd.NewFromString(value)
Expand Down
43 changes: 43 additions & 0 deletions tests/files/const22.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
)

const (
ia = 1_000_000
ib = 1_00_00_00
ic = 1_000

fa = 1_000_000.000
fb = 1_000_000.000_000

// Imaginary number aren't supported at the moment
// ima = 100_000i
// imb = 1 + 100_000i

ha = 0x_16_32
hb = 0b_0110_1001
ho = 0o_644_755
)

func main() {
fmt.Printf("%d\n", ia)
fmt.Printf("%d\n", ib)
fmt.Printf("%d\n", ic)

fmt.Printf("%f\n", fa)
fmt.Printf("%f\n", fb)

fmt.Printf("%x", ha)
fmt.Printf("%x", hb)
fmt.Printf("%x", ho)
}

// Output:
// 1000000
// 1000000
// 1000
// 1000000.000000
// 1000000.000000
// 163269349ed

0 comments on commit 12a5441

Please sign in to comment.