Fix NaN handling in math.intervals

db4
Slava Pestov 2008-07-28 06:31:11 -05:00
parent 9d24828604
commit ed7ad146d8
1 changed files with 6 additions and 4 deletions

View File

@ -1,4 +1,4 @@
! Copyright (C) 2007 Slava Pestov. ! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
! Based on Slate's src/unfinished/interval.slate by Brian Rice. ! Based on Slate's src/unfinished/interval.slate by Brian Rice.
USING: accessors kernel sequences arrays math math.order USING: accessors kernel sequences arrays math math.order
@ -76,9 +76,11 @@ TUPLE: interval { from read-only } { to read-only } ;
[ from>> ] [ to>> ] bi ; [ from>> ] [ to>> ] bi ;
: points>interval ( seq -- interval ) : points>interval ( seq -- interval )
dup first dup [ first fp-nan? ] contains? [ drop [-inf,inf] ] [
[ [ endpoint-min ] reduce ] 2keep dup first
[ endpoint-max ] reduce <interval> ; [ [ endpoint-min ] reduce ] 2keep
[ endpoint-max ] reduce <interval>
] if ;
: (interval-op) ( p1 p2 quot -- p3 ) : (interval-op) ( p1 p2 quot -- p3 )
[ [ first ] [ first ] [ ] tri* call ] [ [ first ] [ first ] [ ] tri* call ]