Changeset 14750


Ignore:
Timestamp:
03/15/17 13:51:37 (2 weeks ago)
Author:
bburlacu
Message:

#2746: Enable explicit overflow checking in binomial coefficient calculation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/EnumerableExtensions.cs

    r14400 r14750  
    150150      if (k > n - k)
    151151        k = n - k;
    152       long r = 1;
    153       for (long d = 1; d <= k; d++) {
    154         r *= n--;
    155         r /= d;
     152
     153      // enable explicit overflow checking for very large coefficients
     154      checked {
     155        long r = 1;
     156        for (long d = 1; d <= k; d++) {
     157          r *= n--;
     158          r /= d;
     159        }
     160        return r;
    156161      }
    157       return r;
    158162    }
    159163  }
Note: See TracChangeset for help on using the changeset viewer.