diff --git a/core/math/integers/integers.factor b/core/math/integers/integers.factor index 6467361a60..d2ecc0336e 100644 --- a/core/math/integers/integers.factor +++ b/core/math/integers/integers.factor @@ -12,7 +12,7 @@ IN: math.integers M: integer numerator ; inline M: integer denominator drop 1 ; inline -M: integer >fraction 1 ; inline +M: integer fraction>parts 1 ; inline M: fixnum >fixnum ; inline M: fixnum >bignum fixnum>bignum ; inline diff --git a/core/math/math.factor b/core/math/math.factor index c70a165673..e082c71fb6 100644 --- a/core/math/math.factor +++ b/core/math/math.factor @@ -84,7 +84,7 @@ GENERIC: integer>fixnum-strict ( x -- y ) foldable GENERIC: numerator ( a/b -- a ) GENERIC: denominator ( a/b -- b ) -GENERIC: >fraction ( a/b -- a b ) +GENERIC: fraction>parts ( a/b -- a b ) GENERIC: real-part ( z -- x ) GENERIC: imaginary-part ( z -- y ) diff --git a/core/math/parser/parser.factor b/core/math/parser/parser.factor index 860c379060..62352d1b18 100644 --- a/core/math/parser/parser.factor +++ b/core/math/parser/parser.factor @@ -480,7 +480,7 @@ M: integer >base } cond ; M: ratio >base - [ >fraction [ /mod ] keep ] [ [ >base ] curry tri@ ] bi* + [ fraction>parts [ /mod ] keep ] [ [ >base ] curry tri@ ] bi* "/" glue over first-unsafe { { char: 0 [ nip ] } { char: - [ append ] } diff --git a/core/math/ratios/ratios-docs.factor b/core/math/ratios/ratios-docs.factor index 57b37f1bb7..66e00415a1 100644 --- a/core/math/ratios/ratios-docs.factor +++ b/core/math/ratios/ratios-docs.factor @@ -17,7 +17,7 @@ $nl { $subsections numerator denominator - >fraction + fraction>parts } { $see-also "syntax-ratios" } ; @@ -37,14 +37,14 @@ HELP: denominator { $values { "a/b" rational } { "b" "a positive integer" } } { $description "Outputs the denominator of a rational number. Always outputs 1 with integers." } ; -HELP: fraction> +HELP: parts>fraction { $values { "a" integer } { "b" "a positive integer" } { "a/b" rational } } { $description "Creates a new ratio, or outputs the numerator if the denominator is 1. This word does not reduce the fraction to lowest terms, and should not be called directly; use " { $link / } " instead." } ; -HELP: >fraction +HELP: fraction>parts { $values { "a/b" rational } { "a" integer } { "b" "a positive integer" } } { $description "Extracts the numerator and denominator of a rational number." } ; -HELP: 2>fraction +HELP: 2fraction>parts { $values { "a/b" rational } { "c/d" rational } { "a" integer } { "c" integer } { "b" "a positive integer" } { "d" "a positive integer" } } { $description "Extracts the numerator and denominator of two rational numbers at once." } ; diff --git a/core/math/ratios/ratios-tests.factor b/core/math/ratios/ratios-tests.factor index 9983351d89..706a1116b2 100644 --- a/core/math/ratios/ratios-tests.factor +++ b/core/math/ratios/ratios-tests.factor @@ -1,6 +1,6 @@ USING: kernel math math.functions math.parser tools.test ; -{ 1 2 } [ 1/2 >fraction ] unit-test +{ 1 2 } [ 1/2 fraction>parts ] unit-test { 1/2 } [ 1 >bignum 2 >bignum / ] unit-test { t } [ 10 3 / ratio? ] unit-test diff --git a/core/math/ratios/ratios.factor b/core/math/ratios/ratios.factor index 669f1c990f..849bc1875a 100644 --- a/core/math/ratios/ratios.factor +++ b/core/math/ratios/ratios.factor @@ -3,22 +3,22 @@ USING: accessors kernel math ; IN: math.ratios -: 2>fraction ( a/b c/d -- a c b d ) - [ >fraction ] bi@ swapd ; inline +: 2fraction>parts ( a/b c/d -- a c b d ) + [ fraction>parts ] bi@ swapd ; inline ( a b -- a/b ) +: parts>fraction ( a b -- a/b ) dup 1 number= [ drop ] [ ratio boa ] if ; inline : (scale) ( a b c d -- a*d b*c ) [ * swap ] dip * swap ; inline : scale ( a/b c/d -- a*d b*c ) - 2>fraction (scale) ; inline + 2fraction>parts (scale) ; inline : scale+d ( a/b c/d -- a*d b*c b*d ) - 2>fraction [ (scale) ] 2keep * ; inline + 2fraction>parts [ (scale) ] 2keep * ; inline PRIVATE> @@ -29,37 +29,37 @@ M: integer / division-by-zero ] [ dup 0 < [ [ neg ] bi@ ] when - 2dup simple-gcd [ /i ] curry bi@ fraction> + 2dup simple-gcd [ /i ] curry bi@ parts>fraction ] if-zero ; M: integer recip 1 swap [ division-by-zero ] [ - dup 0 < [ [ neg ] bi@ ] when fraction> + dup 0 < [ [ neg ] bi@ ] when parts>fraction ] if-zero ; M: ratio recip - >fraction swap dup 0 < [ [ neg ] bi@ ] when fraction> ; + fraction>parts swap dup 0 < [ [ neg ] bi@ ] when parts>fraction ; M: ratio hashcode* - nip >fraction [ hashcode ] bi@ bitxor ; + nip fraction>parts [ hashcode ] bi@ bitxor ; M: ratio equal? over ratio? [ - 2>fraction = [ = ] [ 2drop f ] if + 2fraction>parts = [ = ] [ 2drop f ] if ] [ 2drop f ] if ; M: ratio number= - 2>fraction number= [ number= ] [ 2drop f ] if ; + 2fraction>parts number= [ number= ] [ 2drop f ] if ; -M: ratio >fixnum >fraction /i >fixnum ; -M: ratio >bignum >fraction /i >bignum ; -M: ratio >float >fraction /f ; +M: ratio >fixnum fraction>parts /i >fixnum ; +M: ratio >bignum fraction>parts /i >bignum ; +M: ratio >float fraction>parts /f ; M: ratio numerator numerator>> ; inline M: ratio denominator denominator>> ; inline -M: ratio >fraction [ numerator ] [ denominator ] bi ; inline +M: ratio fraction>parts [ numerator ] [ denominator ] bi ; inline M: ratio < scale < ; M: ratio <= scale <= ; @@ -68,11 +68,11 @@ M: ratio >= scale >= ; M: ratio + scale+d [ + ] [ / ] bi* ; M: ratio - scale+d [ - ] [ / ] bi* ; -M: ratio * 2>fraction [ * ] 2bi@ / ; +M: ratio * 2fraction>parts [ * ] 2bi@ / ; M: ratio / scale / ; M: ratio /i scale /i ; M: ratio /f scale /f ; M: ratio mod scale+d [ mod ] [ / ] bi* ; M: ratio /mod scale+d [ /mod ] [ / ] bi* ; -M: ratio abs dup neg? [ >fraction [ neg ] dip fraction> ] when ; +M: ratio abs dup neg? [ fraction>parts [ neg ] dip parts>fraction ] when ; M: ratio neg? numerator neg? ; inline