Skip to content

Commit da571ce

Browse files
Update predicates.jl
1 parent ff625eb commit da571ce

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/type/predicates.jl

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""
1+
""""
22
__Predicates__ are functions that ask "yes or no" questions of their argument[s].
33
You can ask of a number "Is this zero?" or "Is this one?" and these predicates
44
(`iszero`, `isone`) will work as expected with almost all numerical types.
@@ -16,64 +16,64 @@ These are the predicates made available for use with DoubleFloats:
1616
iseven, isodd, # isinteger(value/2.0), !isinteger(value/2.0)
1717
""" predicates
1818

19-
isnonzero(x::T) where {T<:Real} = !iszero(x)
20-
ispos(x::T) where {T<:Real} = !isneg(x) && isnonzero(x)
21-
isnonneg(x::T) where {T<:Real} = !isneg(x)
22-
isnonpos(x::T) where {T<:Real} = isneg(x) || iszero(x)
23-
isfractional(x::T) where {T<:Real} = abs(x) < one(T)
19+
isnonzero(x::T) where {T<:AbstractFloat} = !iszero(x)
20+
ispos(x::T) where {T<:AbstractFloat} = !isneg(x) && isnonzero(x)
21+
isnonneg(x::T) where {T<:AbstractFloat} = !isneg(x)
22+
isnonpos(x::T) where {T<:AbstractFloat} = isneg(x) || iszero(x)
23+
isfractional(x::T) where {T<:AbstractFloat} = abs(x) < one(T)
2424

2525

26-
iszero(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
26+
iszero(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
2727
iszero(HI(x)) # && iszero(LO(x))
2828

29-
isnonzero(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
29+
isnonzero(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
3030
!iszero(HI(x)) # || !iszero(LO(x))
3131

32-
isone(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
32+
isone(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
3333
isone(HI(x)) && iszero(LO(x))
3434

35-
ispos(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
35+
ispos(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
3636
!signbit(HI(x)) && !iszero(HI(x))
3737

38-
isneg(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
38+
isneg(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
3939
signbit(HI(x))
4040

41-
isnonneg(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
41+
isnonneg(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
4242
!signbit(HI(x))
4343

44-
isnonpos(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
44+
isnonpos(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
4545
signbit(HI(x)) || iszero(HI(x))
4646

47-
isfinite(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
47+
isfinite(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
4848
isfinite(HI(x)) ## && isfinite(LO(x))
4949

50-
isinf(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
50+
isinf(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
5151
isinf(HI(x)) && iszero(LO(x))
5252

53-
isposinf(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
53+
isposinf(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
5454
isinf(HI(x)) && !signbit(HI(x))
5555

56-
isneginf(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
56+
isneginf(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
5757
isinf(HI(x)) && signbit(HI(x))
5858

59-
isnan(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
59+
isnan(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
6060
isnan(HI(x)) ## && iszero(LO(x))
6161

62-
issubnormal(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
62+
issubnormal(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
6363
issubnormal(LO(x)) || issubnormal(HI(x))
6464

65-
isinteger(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
65+
isinteger(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
6666
isinteger(HI(x)) && isinteger(LO(x))
6767

68-
isfractional(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
68+
isfractional(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
6969
!isinteger(LO(x)) || !isinteger(HI(x))
7070

71-
isodd(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
71+
isodd(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
7272
iszero(LO(x)) ?
7373
isinteger(HI(x)) && isodd(HI(x)) :
7474
isinteger(LO(x)) && isodd(LO(x))
7575

76-
iseven(x::Double{T,E}) where {T<:Real,E<:Emphasis} =
76+
iseven(x::Double{T,E}) where {T<:AbstractFloat,E<:Emphasis} =
7777
iszero(LO(x)) ?
7878
isinteger(HI(x)) && iseven(HI(x)) :
7979
isinteger(LO(x)) && iseven(LO(x))

0 commit comments

Comments
 (0)