-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgt-p.robin
61 lines (41 loc) · 1.18 KB
/
gt-p.robin
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
;'<<SPEC'
-> Tests for functionality "Evaluate Robin Expression (with Arith)"
### `gt?` ###
`gt?` evaluates both of its arguments to numbers, then evaluates to `#t`
if the first number is strictly greater than the second.
| (gt? 6 4)
= #t
| (gt? 6 8)
= #f
| (gt? 6 6)
= #f
| (gt? 1610612736 (subtract 0 1610612736)))
= #t
| (gt? (subtract 0 1610612736) 1610612736)
= #f
| (gt? 2147483646 2147483647)
= #f
| (gt? 1 2147483647)
= #f
| (gt? (subtract 0 2147483647) (subtract 0 2147483646))
= #f
| (gt? (subtract 0 2147483647) (subtract 0 1))
= #f
| (gt? 0 (subtract (subtract 0 1073741824) 1073741824)))
= #t
`gt?` expects exactly two arguments, both numbers.
| (gt? 14)
? abort (illegal-arguments
| (gt? 14 23 57)
? abort (illegal-arguments
| (gt? 14 #t)
? abort (expected-number #t)
| (gt? #t 51)
? abort (expected-number #t)
'<<SPEC'
(define gt? (fun (a b)
(bind cmp-same-sign? (fun (a b c)
(equal? (sign (subtract a b)) c))
(if (equal? (sign a) (sign b))
(cmp-same-sign? a b 1)
(cmp-same-sign? (subtract (sign a) 1) (subtract (sign b) 1) 1)))))