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
| 163 | // 10e-7 for 4 bit float |
| 164 | // 10e-16 for 8 bit double |
| 165 | double 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). |