Skip to content

Instantly share code, notes, and snippets.

View danaj's full-sized avatar

Dana Jacobsen danaj

View GitHub Profile
@Marc-B-Reynolds
Marc-B-Reynolds / cbrt.c
Last active May 6, 2025 07:42
bit-exact portable cube root and reciprocal thereof
// Public Domain under http://unlicense.org, see link for details.
// except:
// * core-math function `cr_cbrtf` (see license below)
// * musl flavored fdlib function `fdlibm_cbrtf` (see license below)
// code and test driver for cube root and it's reciprocal based on:
// "Fast Calculation of Cube and Inverse Cube Roots Using
// a Magic Constant and Its Implementation on Microcontrollers"
// Moroz, Samotyy, Walczyk, Cieslinski, 2021
// (PDF: https://www.mdpi.com/1996-1073/14/4/1058)
#!/usr/bin/env perl6
use v6;
use Stats;
#Tim's original times:
#primes-inline-loop(1000) ran in 2.425 seconds (σ = 0.213 seconds).
#primes-inline-loop-upto-sqrt(1000) ran in 2.311 seconds (σ = 0.131 seconds).
#primes-inline-loop-upto-int-sqrt(1000) ran in 2.274 seconds (σ = 0.161).
sub bench($name, &code) {