-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: address issue #20882 #20889
RFC: address issue #20882 #20889
Changes from all commits
35b0543
08c6ccd
75c33fa
e228123
09e5b1b
032a0af
07bc45f
e703ae4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2903,9 +2903,12 @@ end | |
end | ||
|
||
import Base.^ | ||
immutable PR20530; end | ||
struct PR20530; end | ||
struct PR20889; x; end | ||
^(::PR20530, p::Int) = 1 | ||
^{p}(::PR20530, ::Type{Val{p}}) = 2 | ||
^(t::PR20889, b) = t.x + b | ||
^(t::PR20889, b::Integer) = t.x + b | ||
Base.literal_pow{p}(::typeof(^), ::PR20530, ::Type{Val{p}}) = 2 | ||
@testset "literal powers" begin | ||
x = PR20530() | ||
p = 2 | ||
|
@@ -2923,6 +2926,12 @@ immutable PR20530; end | |
end | ||
end | ||
end | ||
@test PR20889(2)^3 == 5 | ||
end | ||
module M20889 # do we get the expected behavior without importing Base.^? | ||
struct PR20889; x; end | ||
^(t::PR20889, b) = t.x + b | ||
Base.Test.@test PR20889(2)^3 == 5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have to put these tests in a different module than the other tests because I'm explicitly testing for what happens when I do not import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right. Don't mind me then. |
||
end | ||
|
||
@testset "iszero" begin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason to stop at 3 rather than e.g. 4? Of course there's virtually no limit, but 4 seems like a common power (much more than 5 and above I'd say). This could help with things like JuliaStats/HypothesisTests.jl#238.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an increasing loss of accuracy at higher powers. This definition for 3 is already inaccurate by a noticeable bit in some cases, so 4+ will potentially be progressively worse from there (though
(x*x)^2
seems pretty well-compensated due to the symmetric shape, as these things go).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks. So are you suggesting we should add a definition using
(x*x)^2
?