Handbook
Glossary
interval
Factor handbook
»
The language
»
Numbers
»
Intervals
Prev:
Properties of interval arithmetic
Next:
interval? ( object -- ? )
Vocabulary
math
.
intervals
Class description
An interval represents a set of real numbers between two endpoints; the endpoints can either be included or excluded from the interval.
The
from
and
to
slots store endpoints, represented as arrays of the shape
{ number included? }
.
Intervals are created by calling
[a,b]
,
(a,b)
,
[a,b)
,
(a,b]
or
[a,a]
.
Definition
IN:
math.intervals
TUPLE:
interval
{
from
read-only
}
{
to
read-only
}
;
Methods
USING:
kernel
math.intervals
math.intervals.private
sequences
;
M:
interval
interval-bounds
interval>points
[
first
]
bi@
;
USING:
accessors
combinators.short-circuit
kernel
math
math.intervals
sequences
;
M:
interval
interval-contains?
{
[
from>>
first2
[
>=
]
[
>
]
if
]
[
to>>
first2
[
<=
]
[
<
]
if
]
}
2&&
;
USING:
kernel
math
math.intervals
sequences
;
M:
interval
interval-length
interval>points
[
first
]
bi@
swap
-
;
USING:
accessors
kernel
layouts
math
math.intervals
math.order
sequences
;
M:
interval
interval-log2
to>>
first
1
max
dup
most-positive-fixnum
>
[
drop
full-interval
interval-log2
]
[
1
+
>integer
log2
[0,b]
]
if
;
USING:
kernel
math
math.intervals
sequences
;
M:
interval
interval-singleton?
interval>points
2dup
[
second
]
both?
[
[
first
]
bi@
number=
]
[
2drop
f
]
if
;
USING:
accessors
db.queries
kernel
math.intervals
nmake
;
M:
interval
where
[
[
from>>
"from"
where-interval
]
[
nip
infinite-interval?
[
" and "
0%
]
unless
]
[
to>>
"to"
where-interval
]
2tri
]
in-parens
;