-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
questionFurther information is requestedFurther information is requested
Milestone
Description
How much should we care about the types of equivalent expressions? For example:
- Given a negative
Int
value ofa
, should(3 ^ a) ^ a
be rewritten to3 ^ (a^2)
, even though this would normally throw an error ifa
isn't converted to a float?
julia> x = -2;
julia> (3 ^ x) ^ x
ERROR: DomainError with -2:
Cannot raise an integer x to a negative power -2.
Make x a float by adding a zero decimal (e.g., 2.0^-2 instead of 2^-2), or write 1/x^2, float(x)^-2, or (x//1)^-2
Stacktrace:
[1] throw_domerr_powbysq(::Int64, ::Int64) at ./intfuncs.jl:176
[2] power_by_squaring(::Int64, ::Int64) at ./intfuncs.jl:196
[3] ^(::Int64, ::Int64) at ./intfuncs.jl:220
[4] top-level scope at none:0
julia> 3 ^ (x^2)
81
- Should
A * 0.0
be rewritten tozero(A)
, even though the resulting value may be of a different type?
julia> A = [1 2; 3 4];
julia> A * 0.0
2×2 Array{Float64,2}:
0.0 0.0
0.0 0.0
julia> zero(A)
2×2 Array{Int64,2}:
0 0
0 0
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested