using if-zero in more places.
parent
80a7329de8
commit
5cc30f46f5
|
@ -165,7 +165,7 @@ M: secure (accept)
|
|||
{ SSL_ERROR_NONE [ 2drop f ] }
|
||||
{ SSL_ERROR_WANT_READ [ 2drop +input+ ] }
|
||||
{ SSL_ERROR_WANT_WRITE [ 2drop +output+ ] }
|
||||
{ SSL_ERROR_SYSCALL [ dup zero? [ 2drop f ] [ syscall-error ] if ] }
|
||||
{ SSL_ERROR_SYSCALL [ [ drop f ] [ syscall-error ] if-zero ] }
|
||||
{ SSL_ERROR_SSL [ (ssl-error) ] }
|
||||
} case ;
|
||||
|
||||
|
|
|
@ -48,11 +48,11 @@ PRIVATE>
|
|||
swap <repetition> seq ;
|
||||
|
||||
: at-most-n ( parser n -- parser' )
|
||||
dup zero? [
|
||||
2drop epsilon
|
||||
[
|
||||
drop epsilon
|
||||
] [
|
||||
[ exactly-n ] [ 1 - at-most-n ] 2bi 2choice
|
||||
] if ;
|
||||
] if-zero ;
|
||||
|
||||
: at-least-n ( parser n -- parser' )
|
||||
dupd exactly-n swap repeat0 2seq
|
||||
|
|
|
@ -59,8 +59,8 @@ M: maybe vocabulary-name
|
|||
] if ;
|
||||
|
||||
: text-fits? ( len -- ? )
|
||||
margin get dup zero?
|
||||
[ 2drop t ] [ [ pprinter get indent>> + ] dip <= ] if ;
|
||||
margin get
|
||||
[ drop t ] [ [ pprinter get indent>> + ] dip <= ] if-zero ;
|
||||
|
||||
! break only if position margin 2 / >
|
||||
SYMBOL: soft
|
||||
|
|
|
@ -54,10 +54,9 @@ M: at-least <times>
|
|||
n>> swap [ repetition ] [ <star> ] bi 2array <concatenation> ;
|
||||
|
||||
: to-times ( term n -- ast )
|
||||
dup zero?
|
||||
[ 2drop epsilon ]
|
||||
[ drop epsilon ]
|
||||
[ dupd 1 - to-times 2array <concatenation> <maybe> ]
|
||||
if ;
|
||||
if-zero ;
|
||||
|
||||
M: from-to <times>
|
||||
[ n>> swap repetition ]
|
||||
|
|
|
@ -5,18 +5,20 @@ IN: math.continued-fractions
|
|||
|
||||
<PRIVATE
|
||||
|
||||
: split-float ( f -- d i ) dup >integer [ - ] keep ;
|
||||
: split-float ( f -- d i )
|
||||
dup >integer [ - ] keep ;
|
||||
|
||||
: closest ( seq -- newseq ) unclip-last round >integer suffix ;
|
||||
: closest ( seq -- newseq )
|
||||
unclip-last round >integer suffix ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: next-approx ( seq -- )
|
||||
dup [ pop split-float ] [ push ] bi
|
||||
dup zero? [ 2drop ] [ recip swap push ] if ;
|
||||
[ drop ] [ recip swap push ] if-zero ;
|
||||
|
||||
: >ratio ( seq -- a/b )
|
||||
closest reverse unclip-slice [ swap recip + ] reduce ;
|
||||
closest reverse! unclip-slice [ swap recip + ] reduce ;
|
||||
|
||||
: approx ( epsilon float -- a/b )
|
||||
dup 1vector
|
||||
|
|
|
@ -53,5 +53,5 @@ IN: math.floating-point
|
|||
[ (double-sign) zero? 1 -1 ? ]
|
||||
[ (double-mantissa-bits) 52 2^ / ]
|
||||
[ (double-exponent-bits) ] tri
|
||||
dup zero? [ 1 + ] [ [ 1 + ] dip ] if 1023 - 2 swap ^ * * ;
|
||||
[ 1 ] [ [ 1 + ] dip ] if-zero 1023 - 2 swap ^ * * ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue