I have a double[] on which a LINQ operation is being performed:
MD = MD.Select(n => n * 100 / MD.Sum()).ToArray();
In some cases, all elements of MD are 0 and then Sum is also zero. Then 0 * 100 = 0 / 0, but it is not giving a divide-by-zero exception or any exception. Why is this so?
Try this:
That won’t throw an exception either: it’ll leave
zas positive infinity. There’s nothing LINQ-specific here – it’s just IEEE-754 floating point arithmetic behaviour.In your case, you’re dividing zero by zero, so you end up with not-a-number.