Skip to content

Commit c428a5f

Browse files
ajkeller34stevengj
authored andcommitted
Remove a type restriction in Base.QuadGK.Segment (#19626) (#19627)
* Remove a type restriction in Base.QuadGK.Segment (#19626) * Test compatibility of quadgk with unitful numbers / physical quantities. * Pare down tests. * More test refinements.
1 parent 44d7677 commit c428a5f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

base/quadgk.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ immutable Segment
4040
a::Number
4141
b::Number
4242
I
43-
E::Real
43+
E
4444
end
4545
isless(i::Segment, j::Segment) = isless(i.E, j.E)
4646

test/math.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,32 @@ end
760760
@test quadgk(cos, 0,0.7,1, norm=abs)[1] sin(1)
761761
end
762762

763+
module Test19626
764+
using Base.Test
765+
766+
# Define a mock physical quantity type
767+
immutable MockQuantity <: Number
768+
val::Float64
769+
end
770+
771+
# Following definitions needed for quadgk to work with MockQuantity
772+
import Base: +, -, *, abs, isnan, isinf, isless
773+
+(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val+b.val)
774+
-(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val-b.val)
775+
*(a::MockQuantity, b::Number) = MockQuantity(a.val*b)
776+
abs(a::MockQuantity) = MockQuantity(abs(a.val))
777+
isnan(a::MockQuantity) = isnan(a.val)
778+
isinf(a::MockQuantity) = isinf(a.val)
779+
isless(a::MockQuantity, b::MockQuantity) = isless(a.val, b.val)
780+
781+
# isapprox only needed for test purposes
782+
Base.isapprox(a::MockQuantity, b::MockQuantity) = isapprox(a.val, b.val)
783+
784+
# Test physical quantity-valued functions
785+
@test quadgk(x->MockQuantity(x), 0.0, 1.0, abstol=MockQuantity(0.0))[1]
786+
MockQuantity(0.5)
787+
end
788+
763789
@testset "subnormal flags" begin
764790
# Ensure subnormal flags functions don't segfault
765791
@test any(set_zero_subnormals(true) .== [false,true])

0 commit comments

Comments
 (0)