
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.016499999910593033) (* 6.28318530718 (* (sqrt (/ u1 (- 1.0 u1))) u2)) (* (sin (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.016499999910593033f) {
tmp = 6.28318530718f * (sqrtf((u1 / (1.0f - u1))) * u2);
} else {
tmp = sinf((6.28318530718f * u2)) * sqrtf(u1);
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: tmp
if ((6.28318530718e0 * u2) <= 0.016499999910593033e0) then
tmp = 6.28318530718e0 * (sqrt((u1 / (1.0e0 - u1))) * u2)
else
tmp = sin((6.28318530718e0 * u2)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.016499999910593033)) tmp = Float32(Float32(6.28318530718) * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * u2)); else tmp = Float32(sin(Float32(Float32(6.28318530718) * u2)) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.016499999910593033)) tmp = single(6.28318530718) * (sqrt((u1 / (single(1.0) - u1))) * u2); else tmp = sin((single(6.28318530718) * u2)) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.016499999910593033:\\
\;\;\;\;6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* (sqrt (/ u1 (- 1.0 u1))) u2)))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (sqrtf((u1 / (1.0f - u1))) * u2);
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = 6.28318530718e0 * (sqrt((u1 / (1.0e0 - u1))) * u2)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * u2)) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (sqrt((u1 / (single(1.0) - u1))) * u2); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (* u1 (* u2 u2)) 39.47841760436263)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(((u1 * (u2 * u2)) * 39.47841760436263f));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt(((u1 * (u2 * u2)) * 39.47841760436263e0))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(Float32(u1 * Float32(u2 * u2)) * Float32(39.47841760436263))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(((u1 * (u2 * u2)) * single(39.47841760436263))); end
\begin{array}{l}
\\
\sqrt{\left(u1 \cdot \left(u2 \cdot u2\right)\right) \cdot 39.47841760436263}
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* u2 (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (u2 * sqrtf(u1));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = 6.28318530718e0 * (u2 * sqrt(u1))
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (u2 * sqrt(u1)); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 0.0)
float code(float cosTheta_i, float u1, float u2) {
return 0.0f;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = 0.0e0
end function
function code(cosTheta_i, u1, u2) return Float32(0.0) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
herbie shell --seed 2024003
(FPCore (cosTheta_i u1 u2)
:name "Trowbridge-Reitz Sample, near normal, slope_y"
:precision binary32
:pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
(* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))