17
Almost the polar opposite if this challenge, and I suspect it will be slightly easier.
Your task is to take two integers in the format a/b
(Forming a rational number) then output the number in decimal exactly.
For example, if you were to input 1/3
, it would output:
0.33333333333333333
And would keep on printing 3s until the end of time, with an optional leading 0. (You could also print one character per line if and only if your language does not allow printing on the same line.)
The behaviour for x/0
will be undefined. For a number that looks like it doesn't repeat (Like, say 5/4
) it actually does repeat. Either of the following two forms would be acceptable for 5/4
:
1.25000000000000000
1.24999999999999999
(The same with whole numbers, 1.9999999
or 2.000000
)
The fraction may not be in its simplest form, and a
or b
may be negative (Note -a/b = -(a/b)
, -a/-b = a/b
, a/-b = -a/b
, and -.6249999
is invalid, but -0.6249999
is acceptable, but you still can use.
Can we use Unix
bc
, or is that cheating? – David R Tribble – 2015-05-04T15:32:20.600Before I keep golfing my answer: Can
a
and/orb
be negative? – Dennis – 2015-05-04T16:18:35.110@Dennis Yes, but either
a
orb
(or both) can be negative) – None – 2015-05-04T16:34:18.247@DavidRTribble I think that's a standard loophole, so no. – None – 2015-05-04T16:34:58.397
Does your latest edit say that leading zeroes are okay with positive numbers, but not negative ones? If so, what's the reason for that? – Geobits – 2015-05-04T16:56:42.227
@Geobits No it says the opposite (
.0
,0.0
,-0.0
are all OK, but-.0
isn't as it looks weird.) – None – 2015-05-04T19:07:18.047Right, that's what I meant, said it backward. So the reason is "it looks weird"? Okay... – Geobits – 2015-05-04T19:12:26.737
Your last edit make some answer invalid (mine, above all). That should be avoided if possible. – edc65 – 2015-05-04T19:56:52.090