-
Notifications
You must be signed in to change notification settings - Fork 1
/
nonstandard.jl
77 lines (68 loc) · 1.77 KB
/
nonstandard.jl
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
import Base: <, iszero, ==, <=, >=, sign, signbit, isinteger, isfinite
export <, iszero, ==, <=, >=, sign, signbit, isinteger, isfinite
function isinteger(a::NumberInterval)
if floor(a) ≺ a ≺ ceil(a)
return false
elseif issingleton(a)
#NOTE given the previous result, singletons must contain single integers
return true
end
return missing_or_exception(a)
end
function isfinite(a::NumberInterval)
# per IEEE standard, intervals cannot contain infinities
if !isempty(a) && !isnan(a)
return true
end
return missing_or_exception(a)
end
for (numberf, setf) in ((:<, :strictprecedes), (:<=, :precedes))
@eval function $numberf(a::NumberInterval, b::NumberInterval)
if $setf(a, b)
return true
elseif $setf(b, a)
return false
end
return missing_or_exception((a, b))
end
end
>=(a::NumberInterval, b::NumberInterval) = b <= a
function iszero(a::NumberInterval)
if !contains_zero(a)
return false
end
if a ⊆ zero(typeof(a))
return true
end
return missing_or_exception(a)
end
function ==(a::NumberInterval, b::NumberInterval)
if isnan(a) || isnan(b)
return false
elseif isdisjoint(a, b)
return false
elseif issingleton(a) && issingleton(b) && a ⊆ b
return true
end
return missing_or_exception((a, b))
end
function sign(a::NumberInterval)
z = zero(typeof(a))
if a ≺ z
return -1
elseif z ≺ a
return +1
elseif a ⊆ z
return 0
end
return missing_or_exception(a)
end
function signbit(a::NumberInterval)
z = zero(typeof(a))
if a ≺ z
return true
elseif precedes(z, a)
return false
end
return missing_or_exception(a)
end