MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / dcombinations

Function dcombinations

libraries/statHelpers/statHelpers.cpp:281–294  ·  view source on GitHub ↗

experimental - not exact but allows large values float (4 bits) works till n = 125 for all k double (8 bits) works till n = 1020 for all k

Source from the content-addressed store, hash-verified

279// float (4 bits) works till n = 125 for all k
280// double (8 bits) works till n = 1020 for all k
281double dcombinations(uint16_t n, uint16_t k)
282{
283 if ((k == 0) || (k == n)) return 1;
284 if (k < (n-k)) k = n - k; // symmetry
285 double rv = n;
286 uint16_t p = 2;
287 for (uint16_t i = n-1; i > k; i--)
288 {
289 rv *= i;
290 rv /= p;
291 p++;
292 }
293 return rv;
294}
295
296
297// recursive (mind your stack and time)

Callers 1

unittestFunction · 0.85

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.68