Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/quadgk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ immutable Segment
a::Number
b::Number
I
E::Real
E
end
isless(i::Segment, j::Segment) = isless(i.E, j.E)

Expand Down
29 changes: 29 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,35 @@ end
@test quadgk(cos, 0,0.7,1, norm=abs)[1] ≈ sin(1)
end

module Test19626
using Base.Test

# Define a mock physical quantity type
immutable MockQuantity{T} <: Number
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it should work now even if it is not a subtype of Number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not a subtype of Number then I get a failure in vecnorm.

val::T
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the <: Number necessary? I wouldn't bother parameterizing the type. Just make val::Float64.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<: Number is necessary, otherwise I get an error from vecnorm.

end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to define promotion rules and conversion for a minimal working example. Just define the minimum number of methods necessary for a test.

# Following definitions needed for quadgk to work with MockQuantity
import Base: +, -, *, abs, isnan, isinf, isless
+(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val+b.val)
-(a::MockQuantity, b::MockQuantity) = MockQuantity(a.val-b.val)
*(a::MockQuantity, b::Number) = MockQuantity(a.val*b)
abs(a::MockQuantity) = MockQuantity(abs(a.val))
isnan(a::MockQuantity) = isnan(a.val)
isinf(a::MockQuantity) = isinf(a.val)
isless(a::MockQuantity, b::MockQuantity) = isless(a.val, b.val)

# isless defn. necessary so that default abstol plays nicely with MockQuantity
isless(y::Number, x::MockQuantity) = y == 0 ? isless(MockQuantity(0), x) :
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just pass abstol = MockQuantity(0.0)

error("Dimensions issue")

# isapprox only needed for test purposes
Base.isapprox(a::MockQuantity, b::MockQuantity) = isapprox(a.val, b.val)

# Test physical quantity-valued functions
@test quadgk(x->MockQuantity(x), 0.0, 1.0)[1] ≈ MockQuantity(0.5)
end

@testset "subnormal flags" begin
# Ensure subnormal flags functions don't segfault
@test any(set_zero_subnormals(true) .== [false,true])
Expand Down