Talk:Convert decimal number to rational

From Rosetta Code
Revision as of 13:48, 12 June 2011 by Util (talk | contribs) (→‎Repetitive digit chains and rounding: Second param for count of repeating digits)

Name change?

To possibly: "Convert decimal number to rational". To make it more descriptive. --Paddy3118 05:59, 12 June 2011 (UTC)

Or "Convert from decimal into a fraction" --Markhobley 08:34, 12 June 2011 (UTC)
What are the plans for results greater than one? Do we want a "top heavy" fraction or whole number and fractional component? What should 3.5 and 7 look like? Presumably we want "7/2" and "7/1" or do we want "3 1/2" and "7"?
Well, since it is not specified, I would think that it is left to the individual, but giving a fraction that is still reducible, such as 5/10 would not feel right. --Paddy3118 11:42, 12 June 2011 (UTC)
Yeah. We definitely need lowest terms.--Markhobley 12:14, 12 June 2011 (UTC)

Decimal?

Are we talking about only rationals? What about 3.14159265...? --Ledrug 06:36, 12 June 2011 (UTC)

Well if you can express it as a finite decimal expansion ... :-)
--Paddy3118 11:44, 12 June 2011 (UTC)
Presumably we are only working to the precision (or double precision) of the system registers, (or to the number of digits originally provided in numerical string based implementations), so the values would all be rational. --Markhobley 12:28, 12 June 2011 (UTC)

Repetitive digit chains and rounding

What do we want to do with chains of repeating sequences such as 0.333333333333? Do we want 111111111111/333333333333 or 333333333333/1000000000000 or do we need to round out the repetitions before evaluation (producing 3/10? or possibly even 1/3). --Markhobley 12:52, 12 June 2011 (UTC)

I recommend allowing a second optional parameter to indicate number of repeating digits. dec2frac(0.1234,2) would mean 0.123434343434... (written as 0.1234 with a bar over the "34), and should convert to 611/4950, while dec2frac(0.1234) or dec2frac(0.1234, 0) would mean *exactly* 0.1234 (1234/10000), which should convert to 617/5000. --Util 13:48, 12 June 2011 (UTC)