32

See here: https://stackoverflow.com/tags/asp.net-vnext/topusers (though it doesn't always happen)

I've recently been retagging some questions and thus removing questions from a given tag. As such, quite often there end up being no questions within the last 7 or last 30 days. It sometimes shows this erroneous result:

0      Last 7 Days     Infinity% unanswered
0      Last 30 Days    Infinity% unanswered  
142    All Time        19.7% unanswered  

Screenshot of Inifinity%

But if I wait a while (presumably due to some caching), it gets fixed to correctly say:

0      Last 7 Days     0% unanswered
0      Last 30 Days    0% unanswered  
142    All Time        19.7% unanswered  
28
  • 16
    If 0 questions are there, any percentage is technically correct. That said, its a pretty funny bug. Commented Feb 5, 2015 at 17:46
  • 52
    They recently hired Buzz Lightyear at the office...
    – animuson StaffMod
    Commented Feb 5, 2015 at 17:54
  • 3
    @BradleyDotNET actually, only 0% would be correct. If there are no questions, then there can be no unanswered questions <_<
    – Compass
    Commented Feb 5, 2015 at 19:00
  • 18
    @Compass Sure, but 100% of 0 is still 0, so is 3% and Infinity percent. Granted Infinity * 0 is undefined, but this isn't Math.SE :) Commented Feb 5, 2015 at 19:01
  • 1
    I get 0% unanswered Commented Feb 5, 2015 at 19:25
  • 1
    @DavidGrinberg "if I wait a while (presumably due to some caching), it gets fixed"
    – Sam
    Commented Feb 5, 2015 at 19:42
  • 9
    I would have expected NaN%, it's 0/0 after all
    – user555045
    Commented Feb 5, 2015 at 20:08
  • 1
    In JavaScript, dividing by 0 gives "Infinity" as the result.
    – Travis J
    Commented Feb 6, 2015 at 19:47
  • 2
    @TravisJ Not if you divide 0 by 0.
    – Ajedi32
    Commented Feb 6, 2015 at 20:01
  • @harold Javascript, you get Infinity, mathmatically, you get undefined, NaN, or NEI.
    – Travis
    Commented Feb 6, 2015 at 20:01
  • @Ajedi32 - # questions / # unanswered would presumably be the set we are looking at. So if there were 0 asked, you are right it would be NaN. If there were any number asked and none answered, we are back to Infinity :)
    – Travis J
    Commented Feb 6, 2015 at 20:03
  • 1
    @TravisJ yes, but nything / 0 = NaN, this is just a JavaScript bug.
    – Travis
    Commented Feb 6, 2015 at 20:05
  • 2
    @Wyatt there's no such "bug", it is perfectly spec'ed behavior. Commented Feb 6, 2015 at 20:06
  • @TravisJ Not quite. If there were any number (n) asked and none answered, then it would be 0/n, not n/0.
    – Ajedi32
    Commented Feb 6, 2015 at 20:06
  • 1
    It's a back-end code bug. Not JavaScript. In C#, 1.0 / 0.0 == Infinity Commented Feb 6, 2015 at 20:06

1 Answer 1

12

Here is a possible explanation, which may be obvious to many of you. One question tagged asp.net-vnext was asked and answered seven days ago. So the code to calculate answered questions returns 1. Perhaps the value 1 is stored in cache. Now the code which calculates total tagged questions executes sometime later. By this time, it is passed seven days, so it returns 0 total questions. When the percentage calculation is done, 1.0 / 0.0 evaluates to Infinity.

double answered = 1;
double total = 0;
double percentage = answered / total * 100;
Console.WriteLine(percentage);//Infinity
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .