This question already has an answer here:
- Print all integers 120 answers
You must write a program or function that will output all decimals with the specified precision if run forever. Example:
0.01, -0.01, 0.02, -0.02, 0.03, -0.03...
The input is the number of decimal places to print. The output is all the numbers with the specified decimal precision (if run forever). It will not output 0.
This challenge has much in common with Print all integers, and the rules are the same:
- The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).
- Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.
- Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.
- The separator must not change at any point.
- The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. , is as valid as just ,). Any supported integer must eventually be printed after a finite amount of time.
But one more additional rule:
- Your submission must support the highest input value / precision possible for floating point arithmetic. You don't have to handle input value beyond that.
Additional test cases:
4 -0.0001 0.0001 -0.0002 0.0002 -0.0003 0.0003...
Note that there can be multiple valid outputs,
0.0001 0.0002 0.0003 -0.0001 -0.0002 -0.0003 0.0004 0.0005 0.0006 -0.0004 -0.0005 -0.0006...
is valid for that last example.
The ellipsis (
...) means more input will follow.