math.ratios: speed up some operations on ratios.
parent
ec6baefce3
commit
e84e508256
|
@ -3,7 +3,7 @@
|
|||
USING: effects accessors kernel kernel.private layouts math
|
||||
math.private math.integers.private math.floats.private
|
||||
math.partial-dispatch math.intervals math.parser math.order
|
||||
math.functions math.libm namespaces words sequences
|
||||
math.functions math.libm math.ratios namespaces words sequences
|
||||
sequences.private arrays assocs classes classes.algebra
|
||||
combinators generic.math splitting fry locals classes.tuple
|
||||
alien.accessors classes.tuple.private slots.private definitions
|
||||
|
@ -239,7 +239,7 @@ generic-comparison-ops [
|
|||
'[ _ swap interval>> <class/interval-info> ] "outputs" set-word-prop
|
||||
] assoc-each
|
||||
|
||||
{ numerator denominator }
|
||||
{ numerator denominator >fraction }
|
||||
[ [ drop integer <class-info> ] "outputs" set-word-prop ] each
|
||||
|
||||
{ (log2) fixnum-log2 bignum-log2 } [
|
||||
|
|
|
@ -4,8 +4,11 @@ USING: math kernel math.constants math.private math.bits
|
|||
math.libm combinators fry math.order sequences ;
|
||||
IN: math.functions
|
||||
|
||||
: >fraction ( a/b -- a b )
|
||||
[ numerator ] [ denominator ] bi ; inline
|
||||
GENERIC: >fraction ( a/b -- a b )
|
||||
|
||||
M: integer >fraction 1 ; inline
|
||||
|
||||
M: ratio >fraction [ numerator ] [ denominator ] bi ; inline
|
||||
|
||||
: rect> ( x y -- z )
|
||||
! Note: an imaginary 0.0 should still create a complex
|
||||
|
|
|
@ -12,11 +12,14 @@ IN: math.ratios
|
|||
: fraction> ( a b -- a/b )
|
||||
dup 1 number= [ drop ] [ ratio boa ] if ; inline
|
||||
|
||||
: scale ( a/b c/d -- a*d b*c )
|
||||
2>fraction [ * swap ] dip * swap ; inline
|
||||
: (scale) ( a b c d -- a*d b*c )
|
||||
[ * swap ] dip * swap ; inline
|
||||
|
||||
: ratio+d ( a/b c/d -- b*d )
|
||||
[ denominator ] bi@ * ; inline
|
||||
: scale ( a/b c/d -- a*d b*c )
|
||||
2>fraction (scale) ; inline
|
||||
|
||||
: scale+d ( a/b c/d -- a*d b*c b*d )
|
||||
2>fraction [ (scale) ] 2keep * ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
@ -66,8 +69,8 @@ M: ratio <= scale <= ;
|
|||
M: ratio > scale > ;
|
||||
M: ratio >= scale >= ;
|
||||
|
||||
M: ratio + [ scale + ] [ ratio+d ] 2bi / ;
|
||||
M: ratio - [ scale - ] [ ratio+d ] 2bi / ;
|
||||
M: ratio + scale+d [ + ] [ / ] bi* ;
|
||||
M: ratio - scale+d [ - ] [ / ] bi* ;
|
||||
M: ratio * 2>fraction [ * ] 2bi@ / ;
|
||||
M: ratio / scale / ;
|
||||
M: ratio /i scale /i ;
|
||||
|
|
Loading…
Reference in New Issue