From 6a7899ccf792d4ea75aa78d8743d71eef2d8a9d8 Mon Sep 17 00:00:00 2001 From: seadra Date: Wed, 20 Apr 2022 23:52:54 -0400 Subject: [PATCH 1/5] Update SpecialFunctions.jl --- src/SpecialFunctions.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SpecialFunctions.jl b/src/SpecialFunctions.jl index c4fe6120..2869a1cd 100644 --- a/src/SpecialFunctions.jl +++ b/src/SpecialFunctions.jl @@ -78,6 +78,7 @@ export expintx, sinint, cosint, + cosint2, lbinomial include("bessel.jl") From ac805454d4f8e21f0a53dc073556af6fc15d517f Mon Sep 17 00:00:00 2001 From: seadra Date: Wed, 20 Apr 2022 23:55:41 -0400 Subject: [PATCH 2/5] Update sincosint.jl --- src/sincosint.jl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/sincosint.jl b/src/sincosint.jl index 783ec6b0..2d4c3293 100644 --- a/src/sincosint.jl +++ b/src/sincosint.jl @@ -216,7 +216,25 @@ function cosint(x::Float64) end end -for f in (:sinint, :cosint) +function cosint2(x::Float64) + y = abs(x) + if y < 16 + z = y/16 + return z*z * @horner(2z-1, + 10.1368932961974, -15.6917864571604, 34.785411496481, -69.112859230540, + 30.440436940418, 86.497485984833, -88.549487075577, -38.143556627179, + 71.651746099402, 4.5789548248084, -33.2018439395653, 2.8893938091092, + 10.4784803469878,-1.78243540010348, -2.44552964739580, 0.54587544934689, + 0.44348693853752, -0.115548604271719, -0.064627744568428, 0.0186536032436421, + 0.0077499317892716, -0.00240942093684089, -0.00077318072365601, 0.000254612753941600, + 0.000061993480895027, -0.0000213920950505084, -3.1668204168001e-6, 1.13680075611623e-6) + else + return MathConstants.eulergamma + log(y) - cosint(y) + end +end + + +for f in (:sinint, :cosint, :cosint2) @eval begin ($f)(x::Float32) = Float32(($f)(Float64(x))) ($f)(x::Float16) = Float16(($f)(Float64(x))) From 308a3639117fe49568b30b2e38a76ffafca343e2 Mon Sep 17 00:00:00 2001 From: seadra Date: Wed, 20 Apr 2022 23:58:15 -0400 Subject: [PATCH 3/5] Update chainrules.jl --- src/chainrules.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chainrules.jl b/src/chainrules.jl index 76a8f07d..52b0b44f 100644 --- a/src/chainrules.jl +++ b/src/chainrules.jl @@ -193,6 +193,7 @@ ChainRulesCore.@scalar_rule( ChainRulesCore.@scalar_rule(expinti(x), exp(x) / x) ChainRulesCore.@scalar_rule(sinint(x), sinc(invπ * x)) ChainRulesCore.@scalar_rule(cosint(x), cos(x) / x) +ChainRulesCore.@scalar_rule(cosint2(x), iszero(x) ? zero(x) : (one(x)-cos(x))/x ) # elliptic integrals ChainRulesCore.@scalar_rule( From 60d9d37cf40b201a47328f66d9d04cdd0ea3bd99 Mon Sep 17 00:00:00 2001 From: seadra Date: Wed, 6 Jul 2022 19:44:09 -0400 Subject: [PATCH 4/5] Update sincosint.jl --- src/sincosint.jl | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/sincosint.jl b/src/sincosint.jl index 2d4c3293..9d8fe2c1 100644 --- a/src/sincosint.jl +++ b/src/sincosint.jl @@ -218,16 +218,9 @@ end function cosint2(x::Float64) y = abs(x) - if y < 16 - z = y/16 - return z*z * @horner(2z-1, - 10.1368932961974, -15.6917864571604, 34.785411496481, -69.112859230540, - 30.440436940418, 86.497485984833, -88.549487075577, -38.143556627179, - 71.651746099402, 4.5789548248084, -33.2018439395653, 2.8893938091092, - 10.4784803469878,-1.78243540010348, -2.44552964739580, 0.54587544934689, - 0.44348693853752, -0.115548604271719, -0.064627744568428, 0.0186536032436421, - 0.0077499317892716, -0.00240942093684089, -0.00077318072365601, 0.000254612753941600, - 0.000061993480895027, -0.0000213920950505084, -3.1668204168001e-6, 1.13680075611623e-6) + if y < 0.5 + z = y*y + return z * @horner(z, 1/4, -1/96, 1/4320, -1/322560, 1/36288000, 1/5748019200) else return MathConstants.eulergamma + log(y) - cosint(y) end From 017be91cb76b1e0b7d204bd30da7791582343eee Mon Sep 17 00:00:00 2001 From: seadra Date: Wed, 6 Jul 2022 21:53:16 -0400 Subject: [PATCH 5/5] Update sincosint.jl --- test/sincosint.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/sincosint.jl b/test/sincosint.jl index 6251111c..4e8d872d 100644 --- a/test/sincosint.jl +++ b/test/sincosint.jl @@ -23,16 +23,22 @@ @test sinint(Float16(1)) == Float16(sinint(1)) @test cosint(Float16(1)) == Float16(cosint(1)) + @test cosint2(Float16(1)) == Float16(cosint2(1)) @test sinint(Float32(1)) == Float32(sinint(1)) @test cosint(Float32(1)) == Float32(cosint(1)) + @test cosint2(Float32(1)) == Float32(cosint2(1)) @test sinint(1//2) == sinint(0.5) @test cosint(1//2) == cosint(0.5) + @test cosint2(1//2) == cosint2(0.5) @test sinint(1e300) ≅ π/2 @test cosint(1e300) ≅ -8.17881912115908554103E-301 @test sinint(1e-300) ≅ 1.0E-300 @test cosint(1e-300) ≅ -690.1983122333121 + + @test cosint2(0.0) == 0.0 + @test cosint2(0.05) ≅ 0.0006249348994501105 # Computed with Mathematica: SetPrecision[EulerGamma + Log[1/20] - CosIntegral[1/20], 20] @test sinint(Inf) == π/2 @test cosint(Inf) == 0.0 @@ -41,10 +47,12 @@ @test_throws ErrorException sinint(big(1.0)) @test_throws ErrorException cosint(big(1.0)) + @test_throws ErrorException cosint2(big(1.0)) @test_throws DomainError cosint(-1.0) @test_throws DomainError cosint(Float32(-1.0)) @test_throws DomainError cosint(Float16(-1.0)) @test_throws DomainError cosint(-1//2) @test_throws MethodError sinint(Complex(1)) @test_throws MethodError cosint(Complex(1)) + @test_throws MethodError cosint2(Complex(1)) end