Skip to content

Commit c2173b3

Browse files
committed
improve style
1 parent 8f5a476 commit c2173b3

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

base/special/trig.jl

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,39 +1189,34 @@ struct _CosCardinalEvaluationScheme{
11891189
end
11901190

11911191
function (sch::_CosCardinalEvaluationScheme)(x::AbstractFloat)
1192+
function choose_poly(a::AbstractFloat, polynomials_close_to_origin::NTuple{2})
1193+
((b1, p0), (_, p1)) = polynomials_close_to_origin
1194+
if a b1
1195+
p0
1196+
else
1197+
p1
1198+
end
1199+
end
1200+
function choose_poly(a::AbstractFloat, polynomials_close_to_origin::NTuple{4})
1201+
((b1, p0), (b2, p1), (b3, p2), (_, p3)) = polynomials_close_to_origin
1202+
if a b2 # hardcoded binary search
1203+
if a b1
1204+
p0
1205+
else
1206+
p1
1207+
end
1208+
else
1209+
if a b3
1210+
p2
1211+
else
1212+
p3
1213+
end
1214+
end
1215+
end
11921216
a = abs(x)
11931217
polynomials_close_to_origin = sch.polynomials_close_to_origin
11941218
if (polynomials_close_to_origin !== ()) && (a polynomials_close_to_origin[end][1])
1195-
let
1196-
if length(polynomials_close_to_origin) == 1 # hardcode for each allowed tuple size
1197-
p = only(polynomials_close_to_origin)[2]
1198-
elseif length(polynomials_close_to_origin) == 2
1199-
p = let ((b1, p0), (_, p1)) = polynomials_close_to_origin
1200-
if a b1 # hardcoded binary search
1201-
p0
1202-
else
1203-
p1
1204-
end
1205-
end
1206-
elseif length(polynomials_close_to_origin) == 4
1207-
p = let ((b1, p0), (b2, p1), (b3, p2), (_, p3)) = polynomials_close_to_origin
1208-
if a b2 # hardcoded binary search
1209-
if a b1
1210-
p0
1211-
else
1212-
p1
1213-
end
1214-
else
1215-
if a b3
1216-
p2
1217-
else
1218-
p3
1219-
end
1220-
end
1221-
end
1222-
end
1223-
x * evalpoly(x * x, p)
1224-
end
1219+
x * evalpoly(x * x, choose_poly(a, polynomials_close_to_origin))
12251220
elseif isinf(x)
12261221
typeof(x)(0)
12271222
else

0 commit comments

Comments
 (0)