How do you get the numerator and denominator of a
rational fraction? For example the (numerator,denominator)
of 4r6 is 2 3; how do you get the 2 3 from 4r6? I know this
must have been covered before, but I cannot think how to
search for it.
My current best effort is the verb ratio.
ratio =: 2{.!.1 (i.&'r' ( {./ , ' ' , ] }.~ #...@] <. >:@[) ])&.":
ratio 4r6
2 3
ratio 4
4
$ratio 4
$ratio 4r6
2
#ratio 4
1
#ratio 4r6
2
ratio"0 ]4r6 6r4 79
2 3
3 2
79 1
--
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm