Skip to content

Commit

Permalink
Implement Global readFloat and isNaN (andyarvanitis#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
emadshaaban92 authored May 9, 2020
1 parent 668e704 commit 6dd6d85
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions purescript-globals/Global.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ package purescript_global
import (
. "github.com/purescript-native/go-runtime"
"math"
"strconv"
)

func init() {
exports := Foreign("Global")

exports["infinity"] = math.Inf(1)

exports["readFloat"] = func(x_ Any) Any {
x, _ := x_.(string)
f, err := strconv.ParseFloat(x, 64)
if err == nil {
return f
}
return math.NaN()
}
exports["isNaN"] = func(x_ Any) Any {
x, _ := x_.(float64)
return math.IsNaN(x)
}

}

0 comments on commit 6dd6d85

Please sign in to comment.