There is a bug in the cbrt function implementation where if the input value is 0, i.e. the mantissa extracted from the input has a value of exactly 0, the resulting output is exactly 0.337986261.
This occurs because the polynomial approximation to the cube root of the mantissa gives a value of 0.402389795 which is very far off. This is normally not an issue because for all non-zero values, the range of inputs to the polynomial approximation is in [0.5, 1), but this guarantee is broken for the case of 0.
Putting that value through the newton-raphson iterations improves the result, but still gives an approximation to the cube root too far away from the true value and thus leads to a final result that is wildly incorrect.
The python API obfuscates this issue because it falls back on math.pow(arg, 1/3) whenever the individual elements of the input are not an array type. e.g. when used in a mitsuba3 scalar_* variant context.
There is a bug in the cbrt function implementation where if the input value is 0, i.e. the mantissa extracted from the input has a value of exactly 0, the resulting output is exactly
0.337986261
.This occurs because the polynomial approximation to the cube root of the mantissa gives a value of
0.402389795
which is very far off. This is normally not an issue because for all non-zero values, the range of inputs to the polynomial approximation is in [0.5, 1), but this guarantee is broken for the case of 0.https://github.com/mitsuba-renderer/drjit/blob/8af56c1d5553c4497dfba0a4409290c4051199b5/include/drjit/math.h#L1446-L1450
Putting that value through the newton-raphson iterations improves the result, but still gives an approximation to the cube root too far away from the true value and thus leads to a final result that is wildly incorrect.
The
python
API obfuscates this issue because it falls back onmath.pow(arg, 1/3)
whenever the individual elements of the input are not an array type. e.g. when used in a mitsuba3 scalar_* variant context.https://github.com/mitsuba-renderer/drjit/blob/8af56c1d5553c4497dfba0a4409290c4051199b5/drjit/router.py#L2899-L2902
I believe a simple solution would be to change the
select
condition fromisfinite(x)
toisfinite(x) && neq(x, 0)
here:https://github.com/mitsuba-renderer/drjit/blob/8af56c1d5553c4497dfba0a4409290c4051199b5/include/drjit/math.h#L1467