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

Function dfactorial

libraries/statHelpers/statHelpers.cpp:165–177  ·  view source on GitHub ↗

FASTER VERSION does part of the math with integers. tested on UNO and ESP32, roughly 3x faster numbers differ slightly in the order of IEEE754 precision => acceptable. 10e-7 for 4 bit float 10e-16 for 8 bit double

Source from the content-addressed store, hash-verified

163// 10e-7 for 4 bit float
164// 10e-16 for 8 bit double
165double dfactorial(uint8_t n)
166{
167 double f = 1;
168 while (n > 4)
169 {
170 uint32_t val = n * (n-1);
171 val *= (n-2) * (n-3);
172 f *= val;
173 n -= 4;
174 }
175 while (n > 1) f *= (n--); // can be squeezed too.
176 return f;
177}
178
179
180// stirling is an approximation function for factorial(n).

Callers 1

unittestFunction · 0.85

Calls

no outgoing calls

Tested by 1

unittestFunction · 0.68