Talk:Getting the number of decimal places

From Rosetta Code
Revision as of 09:31, 16 August 2020 by rosettacode>Paddy3118 (→‎Strings: 12.3450)

Fractions? Trailing Zeros?

What exactly is meant by 'number' in the task description? Fractions are numbers. 1/4 is a fraction whose decimal expansion contains two decimal places. 1/3 is a fraction whose decimal expansion contains an infinite number of decimal places. Are we not meant to handle fractions, even if our language features them as first-class literals?

Can we also get some clarity regarding trailing zeros? Most languages feature numeric types that do not retain trailing zeros. I see that some entries are using strings for these cases instead. Is that intended by the task?

Floating point numbers may also be problematic as mentioned in the Raku entry. By the way, how many decimal places does fp-zero have? How about fp-infinity?

Should we also handle other numeric types with decimal points? Many languages feature some sort of 'BigDecimal' type and complex number type, for example.

It would be nice if the task description could elaborate on some of the above concerns. A restriction of the scope of the task (beyond merely 'numbers'), as well as having an actual task to solve beyond a couple cryptic inputs and outputs would be much appreciated as well. --Chunes (talk) 12:22, 13 August 2020 (UTC)

The description doesn't even exert itself unduly on the question of whether the input value is a String or something else :-)
What is the expected result when the input is pi ?
0 ? (we read pi as a string ?)
Infinity ? (we read pi as bound to a mathematically defined value) ?
Something else ? (we read pi as a system constant, bound to some unspecified member of a zoo of types that might include creatures like f32, f64, i32, i64, i128, or perhaps even their cousins u32, u64, u128, each of which would contain expansions of pi to different digit lengths - most of them zero) ? Hout (talk) 09:10, 14 August 2020 (UTC)
To concretise a little, the initial Python suggestion just errors when the given number is math.e, math.pi, or math.tau, all of which have Python type `float` and are quite hard not to think of as 'numbers', in terms of the task title. Hout (talk) 09:22, 14 August 2020 (UTC)

Strings

The "number of decimals" I took as being a function of how a number is represented. It is either stated implicitly or implied by its string representation. 1.0, 1.00, 1.000, and 1.0000 would all have the same floating point value in Python, but when read can suggest differing levels of precision used in calculating a value, (at least in Physics and Engineering when they pay attention to significant digits). --Paddy3118 (talk) 08:12, 16 August 2020 (UTC)

Normally I would agree, but the reference implementation (Ring) does no string parsing whatsoever as far as I can tell. --Chunes (talk) 08:45, 16 August 2020 (UTC)
And if this were really intended as a function over a string (the reference implementation and task description both indicate otherwise), it would be far too trivial to be worth promoting to task status. Hout (talk) 08:54, 16 August 2020 (UTC)

Just trying to bring some meaning to an obscure description. What other way is there to distinguish 12.3450 of the description from 12.345 or 12.34500 in Python (and a lot of other languages)? --Paddy3118 (talk) 09:31, 16 August 2020 (UTC)