hm ...
>>> def percent(progress, total):
... return round(99 * progress / total + 0.5)
...
>>> x = 9007199254740990.0
>>> x - 1 >> percent(x - 1, x)
10021–30 of 30 posts
hm ...
>>> def percent(progress, total):
... return round(99 * progress / total + 0.5)
...
>>> x = 9007199254740990.0
>>> x - 1 >> percent(x - 1, x)
100Earlier quoted context omitted.
Problem is the rounding in the text: 12.1 MB of 12.1 MB downloaded. You can't see if this is 99% or not. All digits even become difficult with large numbers: 175.464.272 of 175.484.272 downloaded (i.e. not 100%).
How about "N remaining"? Anything that isn't zero means it's still in progress or stalled. Only abbreviate (via thousands indicators like K, M, G, etc.) when it actually shortens the text meaningfully, so there will be no truncation or rounding toward the end.
Personally, "0%" doesn't mean "hasn't started" to me, it means "not enough progress has happened to reach 1%". Assuming I'm not alone with that, the rounding becomes a simple truncation `roundedPercent = int(percent)`
An implementation as simple as the concept, which is a good sign in my experience
> If your language has bad defaults, you may have to ask for the right rounding mode explicitly. Is the author implying Rust's default rounding behavior is a bad default? In what world is "ties to even" a GOOD default?
Feels like having some standard plan + execution status interface would at least force you to consider a whole process even if that multistep plan is basically hardcoded.
But then, I'm a Unix hacker. ;)
> float hm ... >>> def percent(progress, total): ... return round(99 * progress / total + 0.5) ... >>> x = 9007199254740990.0 >>> x - 1 >> percent(x - 1, x) 100
>>> x = 9007199254740990
>>> percent(x - 1, x)
99
But then again, >>> percent(10 * x - 1, 10 * x)
100
If your procedure has 2^53 steps, feel free to ignore my rounding recommendations, since I'll never see it get anywhere near 100% :)Also if your username is named after the band, good taste :)
> If your language has bad defaults, you may have to ask for the right rounding mode explicitly. Is the author implying Rust's default rounding behavior is a bad default? In what world is "ties to even" a GOOD default?
https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even
> float hm ... >>> def percent(progress, total): ... return round(99 * progress / total + 0.5) ... >>> x = 9007199254740990.0 >>> x - 1 >> percent(x - 1, x) 100
You're cheating by using floating-point arguments; they should be integers: >>> x = 9007199254740990 >>> percent(x - 1, x) 99 But then again, >>> percent(10 * x - 1, 10 * x) 100 If your procedure has 2^53 steps, feel free to ignore my rounding recommendations, since I'll never see it get anywhere near 100% :) Also if your username is named after the band, good taste :)
i am not cheating; you are cheating by trying to do integer arithmetic instead of float arithmetic. in particular: 99 * progress is a (potentially big) integer; then the quotient, from my understanding of python, is equal to the mathematical quantity rn(99 * progress / total), which is not trivial to compute. (although cpython does tend to do a particularly bad job of this sort of thing.) (compare with c or with my version of the python, where it would be rn(rn(99 * progress) / rn(total)), rounding twice, which is very easy to compute. i'm not saying the c semantics is better, mind.) when you scale up by 10x, the numerator is i agree it is not common to have so many steps. but if i were providing a routine that was intended to be robust where others were not, i would try to be comprehensive. and i would not try to do int math with floats unless i could show it to be robust (i have sketched such a stunt! https://gist.github.com/moon-chilled/60bd2ba687dc197d93a9d22...). the integer routine is simpler and more honest anyway, and it is obvious that it works uniformly for the entire range
note also that, with x floating, the python expressions 10 * x and 10 * x - 1 are equivalent, meaning the error is on input to the percent function. (if we set progress to 10 * x - 8, the immediately preceding fp number, we do get 99, but there is no deep reason for this, and it differs for different values of 10.)
> if your username is named after the band, good taste :)
my username comes from a book: the neverending story. i am more using the german version of the name these days but i do not feel like making a new account on this godforesaken website