\frac{1 - \cos x}{x \cdot x}\begin{array}{l}
\mathbf{if}\;x \le -0.0266096722673715806:\\
\;\;\;\;\frac{1}{x} \cdot \frac{\mathsf{log1p}\left(\mathsf{expm1}\left(1 - \cos x\right)\right)}{x}\\
\mathbf{elif}\;x \le 0.0240834512536182467:\\
\;\;\;\;\mathsf{fma}\left({x}^{2}, \frac{-1}{24}, \mathsf{fma}\left(\frac{1}{720}, {x}^{4}, \frac{1}{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1 - \cos x}{x}}{x}\right)\right)\\
\end{array}double f(double x) {
double r25054 = 1.0;
double r25055 = x;
double r25056 = cos(r25055);
double r25057 = r25054 - r25056;
double r25058 = r25055 * r25055;
double r25059 = r25057 / r25058;
return r25059;
}
double f(double x) {
double r25060 = x;
double r25061 = -0.02660967226737158;
bool r25062 = r25060 <= r25061;
double r25063 = 1.0;
double r25064 = r25063 / r25060;
double r25065 = 1.0;
double r25066 = cos(r25060);
double r25067 = r25065 - r25066;
double r25068 = expm1(r25067);
double r25069 = log1p(r25068);
double r25070 = r25069 / r25060;
double r25071 = r25064 * r25070;
double r25072 = 0.024083451253618247;
bool r25073 = r25060 <= r25072;
double r25074 = 2.0;
double r25075 = pow(r25060, r25074);
double r25076 = -0.041666666666666664;
double r25077 = 0.001388888888888889;
double r25078 = 4.0;
double r25079 = pow(r25060, r25078);
double r25080 = 0.5;
double r25081 = fma(r25077, r25079, r25080);
double r25082 = fma(r25075, r25076, r25081);
double r25083 = r25067 / r25060;
double r25084 = r25083 / r25060;
double r25085 = log1p(r25084);
double r25086 = expm1(r25085);
double r25087 = r25073 ? r25082 : r25086;
double r25088 = r25062 ? r25071 : r25087;
return r25088;
}



Bits error versus x
if x < -0.02660967226737158Initial program 0.9
rmApplied *-un-lft-identity0.9
Applied times-frac0.5
rmApplied log1p-expm1-u0.5
if -0.02660967226737158 < x < 0.024083451253618247Initial program 62.2
Taylor expanded around 0 0.0
Simplified0.0
if 0.024083451253618247 < x Initial program 1.0
rmApplied *-un-lft-identity1.0
Applied times-frac0.5
rmApplied log1p-expm1-u0.5
rmApplied expm1-log1p-u0.5
Simplified0.4
Final simplification0.2
herbie shell --seed 2020046 +o rules:numerics
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1 (cos x)) (* x x)))