Maybe this should be a common utility in math.h? Similar to the bottom of src/effects/native/reverb/basics.h