Skip to content

Commit

Permalink
wdte: Fix comparison of floats. (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeedleFake committed Jun 27, 2019
1 parent f0eaaa4 commit 0aeaf58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 10 additions & 3 deletions types.go
Expand Up @@ -113,11 +113,18 @@ func (n Number) Call(frame Frame, args ...Func) Func { // nolint

func (n Number) Compare(other Func) (int, bool) { // nolint
o, ok := other.(Number)
if !ok {

switch {
case !ok:
return -1, false
}

return int(n - o), true
case n < o:
return -1, true
case n > o:
return 1, true
default:
return 0, true
}
}

func (n Number) String() string { // nolint
Expand Down
5 changes: 5 additions & 0 deletions wdte_test.go
Expand Up @@ -190,6 +190,11 @@ func TestBasics(t *testing.T) {
script: `let test => +; test 3 5;`,
ret: wdte.Number(8),
},
{
name: "Simple/Number/Compare",
script: `[< .2 .5; < .6 .5; > .2 .5; > .6 .5];`,
ret: wdte.Array{wdte.Bool(true), wdte.Bool(false), wdte.Bool(false), wdte.Bool(true)},
},
{
name: "Simple/String/Compare",
script: `[< 'a' 'b'; > 'a' 'b'];`,
Expand Down

0 comments on commit 0aeaf58

Please sign in to comment.