Skip to content

Commit

Permalink
Fixes boolean compare and rename one function
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Jun 21, 2024
1 parent 10ac875 commit 666a073
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## Unreleased

### Added

### Changed

- Changed `Num.( = )` to `Num.equal` to be more consistent with other modules

### Fixed

- Fixed comparison of boolean values

## v0.1.2

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/num.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type t =
| F32 of int32
| F64 of int64

let ( = ) (n1 : t) (n2 : t) : bool =
let equal (n1 : t) (n2 : t) : bool =
match (n1, n2) with
| I8 i1, I8 i2 -> i1 = i2
| I32 i1, I32 i2 -> i1 = i2
Expand Down
2 changes: 1 addition & 1 deletion lib/num.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type t =
| F32 of int32
| F64 of int64

val ( = ) : t -> t -> bool
val equal : t -> t -> bool

val compare : t -> t -> int

Expand Down
4 changes: 3 additions & 1 deletion lib/value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ let equal (v1 : t) (v2 : t) : Bool.t =
| Int x1, Int x2 -> Int.equal x1 x2
| Real x1, Real x2 -> x1 = x2
| Str x1, Str x2 -> String.equal x1 x2
| Num x1, Num x2 -> Num.(x1 = x2)
| Num x1, Num x2 -> Num.equal x1 x2
| _ -> false

let compare v1 v2 =
match (v1, v2) with
| True, True | False, False -> 0
| False, True -> -1
| True, False -> 1
| Int x1, Int x2 -> Int.compare x1 x2
| Real x1, Real x2 -> Float.compare x1 x2
| Str x1, Str x2 -> String.compare x1 x2
Expand Down
2 changes: 1 addition & 1 deletion test/regression/test_pr_77.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let () =
assert (
let nan0 = F32 (Int32.bits_of_float Float.nan) in
let nan1 = F32 (Int32.bits_of_float Float.nan) in
not Num.(nan0 = nan1) )
not (Num.equal nan0 nan1) )

let () =
let open Expr.Fpa in
Expand Down

0 comments on commit 666a073

Please sign in to comment.