File: float_compare.ml

package info (click to toggle)
js-of-ocaml 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 37,932 kB
  • sloc: ml: 135,957; javascript: 58,364; ansic: 437; makefile: 422; sh: 12; perl: 4
file content (113 lines) | stat: -rw-r--r-- 2,804 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(* TEST *)

let equal (x : float) (y : float) =
  x, "=", y, (x = y)
[@@inline never]

let not_equal (x : float) (y : float) =
  x, "!=", y, (x <> y)
[@@inline never]

let less_than (x : float) (y : float) =
  x, "<", y, (x < y)
[@@inline never]

let not_less_than (x : float) (y : float) =
  x, "!<", y, not (x < y)
[@@inline never]

let less_equal (x : float) (y : float) =
  x, "<=", y, (x <= y)
[@@inline never]

let not_less_equal (x : float) (y : float) =
  x, "!<=", y, not (x <= y)
[@@inline never]

let greater_than (x : float) (y : float) =
  x, ">", y, (x > y)
[@@inline never]

let not_greater_than (x : float) (y : float) =
  x, "!>", y, not (x > y)
[@@inline never]

let greater_equal (x : float) (y : float) =
  x, ">=", y, (x >= y)
[@@inline never]

let not_greater_equal (x : float) (y : float) =
  x, "!>=", y, not (x >= y)
[@@inline never]

let show (x, op, y, b) =
  print_float x;
  print_string " ";
  print_string op;
  print_string " ";
  print_float y;
  print_string ": ";
  print_endline (string_of_bool b)

let print_line () =
  print_endline "------------------"

let () = show (equal 1.0 2.0)
let () = show (equal 1.0 1.0)
let () = show (equal 2.0 1.0)
let () = show (equal 1.0 nan)
let () = print_line ()

let () = show (not_equal 1.0 2.0)
let () = show (not_equal 1.0 1.0)
let () = show (not_equal 2.0 1.0)
let () = show (not_equal 1.0 nan)
let () = print_line ()

let () = show (less_than 1.0 2.0)
let () = show (less_than 1.0 1.0)
let () = show (less_than 2.0 1.0)
let () = show (less_than 1.0 nan)
let () = print_line ()

let () = show (not_less_than 1.0 2.0)
let () = show (not_less_than 1.0 1.0)
let () = show (not_less_than 2.0 1.0)
let () = show (not_less_than 1.0 nan)
let () = print_line ()

let () = show (less_equal 1.0 2.0)
let () = show (less_equal 1.0 1.0)
let () = show (less_equal 2.0 1.0)
let () = show (less_equal 1.0 nan)
let () = print_line ()

let () = show (not_less_equal 1.0 2.0)
let () = show (not_less_equal 1.0 1.0)
let () = show (not_less_equal 2.0 1.0)
let () = show (not_less_equal 1.0 nan)
let () = print_line ()

let () = show (greater_than 1.0 2.0)
let () = show (greater_than 1.0 1.0)
let () = show (greater_than 2.0 1.0)
let () = show (greater_than 1.0 nan)
let () = print_line ()

let () = show (not_greater_than 1.0 2.0)
let () = show (not_greater_than 1.0 1.0)
let () = show (not_greater_than 2.0 1.0)
let () = show (not_greater_than 1.0 nan)
let () = print_line ()

let () = show (greater_equal 1.0 2.0)
let () = show (greater_equal 1.0 1.0)
let () = show (greater_equal 2.0 1.0)
let () = show (greater_equal 1.0 nan)
let () = print_line ()

let () = show (not_greater_equal 1.0 2.0)
let () = show (not_greater_equal 1.0 1.0)
let () = show (not_greater_equal 2.0 1.0)
let () = show (not_greater_equal 1.0 nan)
let () = print_line ()