Skip to content

Commit e933115

Browse files
committed
improve style
1 parent 4f86cf3 commit e933115

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
@@ -1190,39 +1190,34 @@ struct _CosCardinalEvaluationScheme{
11901190
end
11911191

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

0 commit comments

Comments
 (0)