Skip to content
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

Integer exponentiation for immutables of 3 or 4 (maybe more) floats broken #6734

Closed
twadleigh opened this issue May 3, 2014 · 1 comment
Closed

Comments

@twadleigh
Copy link
Contributor

Floating point exponentiation appears to work for all the types.

Integer exponentiation now appears to work for all tuples, although for a while it was also broken for 3-tuples. Integer exponentiation also seems to work for immutables of two floats, but not 3 or 4.

This regression first appeared with fa315c9. Discussion on that thread suggests that the problem may be in LLVM (which puts it beyond my capability to track down further).

Some test code:

function test(a,n,b)
    an = a.^n
    pf = an == b ? "pass" : "fail"
    println("$a.^$n == $an; $pf")
end

.^(v::(Float64,Float64),n::Number) = (v[1].^n,v[2].^n)
.^(v::(Float64,Float64,Float64),n::Number) = (v[1].^n,v[2].^n,v[3].^n)
.^(v::(Float64,Float64,Float64,Float64),n::Number) = (v[1].^n,v[2].^n,v[3].^n,v[4].^n)

immutable V2
    x :: Float64
    y :: Float64
end

.^(v::V2, n::Number) = V2(v.x.^n,v.y.^n)

immutable V3
    x :: Float64
    y :: Float64
    z :: Float64
end

.^(v::V3, n::Number) = V3(v.x.^n,v.y.^n,v.z.^n)

immutable V4
    x :: Float64
    y :: Float64
    z :: Float64
    w :: Float64
end

.^(v::V4, n::Number) = V4(v.x.^n,v.y.^n,v.z.^n,v.w.^n)

t2  = (1.0,2.0)
t22 = (1.0,4.0)
t3  = (1.0,2.0,3.0)
t32 = (1.0,4.0,9.0)
t4  = (1.0,2.0,3.0,4.0)
t42 = (1.0,4.0,9.0,16.0)
v2  = V2(1.0,2.0)
v22 = V2(1.0,4.0)
v3  = V3(1.0,2.0,3.0)
v32 = V3(1.0,4.0,9.0)
v4  = V4(1.0,2.0,3.0,4.0)
v42 = V4(1.0,4.0,9.0,16.0)

for case in [ (t2,t22), (t3,t32), (t4,t42), (v2,v22), (v3,v32), (v4,v42) ]
    test(case[1],2.0,case[2])
    test(case[1],2,case[2])
end

produces:

(1.0,2.0).^2.0 == (1.0,4.0); pass
(1.0,2.0).^2 == (1.0,4.0); pass
(1.0,2.0,3.0).^2.0 == (1.0,4.0,9.0); pass
(1.0,2.0,3.0).^2 == (1.0,4.0,9.0); pass
(1.0,2.0,3.0,4.0).^2.0 == (1.0,4.0,9.0,16.0); pass
(1.0,2.0,3.0,4.0).^2 == (1.0,4.0,9.0,16.0); pass
V2(1.0,2.0).^2.0 == V2(1.0,4.0); pass
V2(1.0,2.0).^2 == V2(1.0,4.0); pass
V3(1.0,2.0,3.0).^2.0 == V3(1.0,4.0,9.0); pass
V3(1.0,2.0,3.0).^2 == V3(9.0,9.0,NaN); fail
V4(1.0,2.0,3.0,4.0).^2.0 == V4(1.0,4.0,9.0,16.0); pass
V4(1.0,2.0,3.0,4.0).^2 == V4(16.0,16.0,NaN,NaN); fail
@JeffBezanson
Copy link
Member

dup of #6506

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants