1

This code produces a System.ArgumentOutOfRangeException because numberOfIntervals is infinity. But why doesn't this produce a divide by zero exception? The calculation ends up being -524 / 0. Shouldn't that produce a divide by zero exception?

DateTime startDate = new DateTime(2019, 1, 1);
DateTime referenceDate = new DateTime(2020, 6, 8);

double numberOfIntervals = (startDate - referenceDate).TotalDays / 0;

Console.WriteLine(numberOfIntervals);
Bob Horn
  • 33,387
  • 34
  • 113
  • 219

1 Answers1

3

The implementation is done by IEEE 754 standard.

Division by zero: an operation on finite operands gives an exact infinite result, e.g., 1/0 or log(0). By default, returns ±infinity.

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
  • I see that in the exception handling section: https://en.wikipedia.org/wiki/IEEE_754#Exception_handling I guess I'm still wondering why treat double differently than int. – Bob Horn Jun 11 '20 at 17:14
  • 1
    Maybe this can help https://en.wikipedia.org/wiki/Division_by_zero – Sir Rufo Jun 11 '20 at 17:18