
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* (* uy 2.0) (PI)))
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux))))\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 58.8%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites57.3%
Taylor expanded in ux around 0
Applied rewrites98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1
(sqrt
(fma (- ux (fma ux maxCos 1.0)) (fma ux maxCos (- 1.0 ux)) 1.0)))
(t_2 (* (PI) 2.0)))
(if (<=
(* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))
0.0002500000118743628)
(*
(* t_2 uy)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux)))
(*
(fma
(* t_1 (* (* (* (PI) (PI)) (PI)) (* uy uy)))
-1.3333333333333333
(* t_2 t_1))
uy))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \sqrt{\mathsf{fma}\left(ux - \mathsf{fma}\left(ux, maxCos, 1\right), \mathsf{fma}\left(ux, maxCos, 1 - ux\right), 1\right)}\\
t_2 := \mathsf{PI}\left(\right) \cdot 2\\
\mathbf{if}\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0} \leq 0.0002500000118743628:\\
\;\;\;\;\left(t\_2 \cdot uy\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(uy \cdot uy\right)\right), -1.3333333333333333, t\_2 \cdot t\_1\right) \cdot uy\\
\end{array}
\end{array}
if (*.f32 (sin.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)))))) < 2.50000012e-4Initial program 52.3%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites50.5%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in uy around 0
Applied rewrites86.8%
if 2.50000012e-4 < (*.f32 (sin.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)))))) Initial program 80.2%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-neg.f3279.6
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3279.6
Applied rewrites79.6%
Taylor expanded in uy around 0
Applied rewrites71.9%
Applied rewrites71.9%
Final simplification83.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (fma (fma (- 2.0 maxCos) ux -2.0) maxCos 2.0) ux) ux)) (sin (* (PI) (* uy 2.0)))))
\begin{array}{l}
\\
\sqrt{\left(\mathsf{fma}\left(\mathsf{fma}\left(2 - maxCos, ux, -2\right), maxCos, 2\right) - ux\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 58.8%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3298.4
Applied rewrites98.4%
Taylor expanded in ux around 0
Applied rewrites98.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (fma (fma 2.0 ux -2.0) maxCos 2.0) ux) ux)) (sin (* (PI) (* uy 2.0)))))
\begin{array}{l}
\\
\sqrt{\left(\mathsf{fma}\left(\mathsf{fma}\left(2, ux, -2\right), maxCos, 2\right) - ux\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 58.8%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3298.4
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 6.500000017695129e-5)
(*
(* (* (PI) 2.0) uy)
(sqrt
(* (- (fma (- (fma (- ux) maxCos -2.0) (* -2.0 ux)) maxCos 2.0) ux) ux)))
(* (sin (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 ux) ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 6.500000017695129 \cdot 10^{-5}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\mathsf{fma}\left(\mathsf{fma}\left(-ux, maxCos, -2\right) - -2 \cdot ux, maxCos, 2\right) - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\end{array}
\end{array}
if uy < 6.50000002e-5Initial program 58.7%
Taylor expanded in ux around 0
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.6%
Taylor expanded in uy around 0
Applied rewrites98.6%
if 6.50000002e-5 < uy Initial program 58.8%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites95.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- (fma -2.0 maxCos 2.0) ux) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\mathsf{fma}\left(-2, maxCos, 2\right) - ux\right) \cdot ux}
\end{array}
Initial program 58.8%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
Taylor expanded in ux around 0
Applied rewrites97.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (PI) 2.0)))
(if (<= (* t_0 t_0) 0.9997599720954895)
(*
(*
t_1
(sqrt (fma (- ux (fma ux maxCos 1.0)) (fma ux maxCos (- 1.0 ux)) 1.0)))
uy)
(* (* t_1 uy) (sqrt (* (- (fma -1.0 maxCos 2.0) maxCos) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \mathsf{PI}\left(\right) \cdot 2\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9997599720954895:\\
\;\;\;\;\left(t\_1 \cdot \sqrt{\mathsf{fma}\left(ux - \mathsf{fma}\left(ux, maxCos, 1\right), \mathsf{fma}\left(ux, maxCos, 1 - ux\right), 1\right)}\right) \cdot uy\\
\mathbf{else}:\\
\;\;\;\;\left(t\_1 \cdot uy\right) \cdot \sqrt{\left(\mathsf{fma}\left(-1, maxCos, 2\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999759972Initial program 89.9%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-neg.f3289.8
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3289.8
Applied rewrites89.8%
Taylor expanded in uy around 0
Applied rewrites84.2%
Taylor expanded in uy around 0
Applied rewrites75.0%
if 0.999759972 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 38.1%
Taylor expanded in uy around 0
Applied rewrites35.0%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f32N/A
Applied rewrites32.6%
Taylor expanded in ux around 0
Applied rewrites75.5%
Final simplification75.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.9994999766349792)
(* t_1 (sqrt (- 1.0 (* t_0 (- 1.0 ux)))))
(* t_1 (sqrt (* (- (fma -1.0 maxCos 2.0) maxCos) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9994999766349792:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(\mathsf{fma}\left(-1, maxCos, 2\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999499977Initial program 91.5%
Taylor expanded in uy around 0
Applied rewrites75.8%
Taylor expanded in maxCos around 0
Applied rewrites73.3%
if 0.999499977 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 39.8%
Taylor expanded in uy around 0
Applied rewrites36.2%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f32N/A
Applied rewrites34.1%
Taylor expanded in ux around 0
Applied rewrites74.8%
Final simplification74.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.9994999766349792)
(* t_1 (sqrt (fma (- ux 1.0) (- 1.0 ux) 1.0)))
(* t_1 (sqrt (* (- (fma -1.0 maxCos 2.0) maxCos) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9994999766349792:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(ux - 1, 1 - ux, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(\mathsf{fma}\left(-1, maxCos, 2\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999499977Initial program 91.5%
Taylor expanded in uy around 0
Applied rewrites75.8%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f32N/A
Applied rewrites75.8%
Taylor expanded in maxCos around 0
Applied rewrites73.1%
if 0.999499977 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 39.8%
Taylor expanded in uy around 0
Applied rewrites36.2%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f32N/A
Applied rewrites34.1%
Taylor expanded in ux around 0
Applied rewrites74.8%
Final simplification74.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.9994999766349792)
(* t_1 (sqrt (fma (- ux 1.0) (- 1.0 ux) 1.0)))
(* t_1 (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9994999766349792:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(ux - 1, 1 - ux, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999499977Initial program 91.5%
Taylor expanded in uy around 0
Applied rewrites75.8%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f32N/A
Applied rewrites75.8%
Taylor expanded in maxCos around 0
Applied rewrites73.1%
if 0.999499977 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 39.8%
Taylor expanded in uy around 0
Applied rewrites36.2%
Taylor expanded in ux around 0
Applied rewrites74.8%
Final simplification74.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux))))\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 58.8%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
Applied rewrites57.3%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in uy around 0
Applied rewrites79.2%
Final simplification79.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (- (fma (- (fma (- ux) maxCos -2.0) (* -2.0 ux)) maxCos 2.0) ux) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\mathsf{fma}\left(\mathsf{fma}\left(-ux, maxCos, -2\right) - -2 \cdot ux, maxCos, 2\right) - ux\right) \cdot ux}
\end{array}
Initial program 58.8%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
Taylor expanded in uy around 0
Applied rewrites79.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.8%
Taylor expanded in ux around 0
Applied rewrites64.0%
Final simplification64.0%
(FPCore (ux uy maxCos) :precision binary32 (* (+ uy uy) (sqrt (- 1.0 1.0))))
float code(float ux, float uy, float maxCos) {
return (uy + uy) * sqrtf((1.0f - 1.0f));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (uy + uy) * sqrt((1.0e0 - 1.0e0))
end function
function code(ux, uy, maxCos) return Float32(Float32(uy + uy) * sqrt(Float32(Float32(1.0) - Float32(1.0)))) end
function tmp = code(ux, uy, maxCos) tmp = (uy + uy) * sqrt((single(1.0) - single(1.0))); end
\begin{array}{l}
\\
\left(uy + uy\right) \cdot \sqrt{1 - 1}
\end{array}
Initial program 58.8%
Taylor expanded in uy around 0
Applied rewrites50.8%
Taylor expanded in ux around 0
Applied rewrites7.1%
Applied rewrites7.1%
Applied rewrites7.1%
herbie shell --seed 2025019
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))