example.org 1.4 KB

General information

Reals cannot be compared using:

  • =
  • <>

This is because calculations with IEEE754 floats can have imprecise results and different results depending on the order of operation, which would not matter for truly real numbers. To protect the programmer from calculation mistakes when dealing with IEEE754 floats, these comparisons are forbidden to be used on reals.

Number comparisons

1 = 1; 2 > 1; 1 < 2; 2 <> 1; 2 >= 1; 1 <= 2; 1.0 = 1.0; 1.0 <> 2.0; (error) 1.0 <= 2.0; (error)

:results: val it = true : bool :end:

String comparisons

(lexicographic ordering)

"abc" < "def"; "abc" <= "def"; "abc" > "def"; "abc" >= "def"; "abc" <> "def"; "abc" = "def";

:results: val it = true : bool :end:

Character comparisons

(lexicographically precedes)

#"a" < #"b"; #"a" <= #"b"; #"a" > #"b"; #"a" >= #"b"; #"a" <> #"b"; #"a" = #"b";

:results: val it = true : bool :end: