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