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

No type promotion for arithmetics of mixed types #128

Closed
favba opened this issue Sep 17, 2024 · 2 comments
Closed

No type promotion for arithmetics of mixed types #128

favba opened this issue Sep 17, 2024 · 2 comments

Comments

@favba
Copy link
Contributor

favba commented Sep 17, 2024

Current behavior:

julia> a = Vec(1,2)
<2 x Int64>[1, 2]

julia> b = Vec(1.,2.)
<2 x Float64>[1.0, 2.0]

julia> a + b
ERROR: MethodError: no method matching +(::Vec{2, Int64}, ::Vec{2, Float64})
...

julia> a*b
ERROR: MethodError: no method matching *(::Vec{2, Int64}, ::Vec{2, Float64})
...
@KristofferC
Copy link
Collaborator

I think this is kind of intended. When you do SIMD stuff you want to be very explicit in my opinion and doing arithmetic between different number types is kind of rare in practice and in those cases you can always do the conversion explicitly.

@favba
Copy link
Contributor Author

favba commented Sep 17, 2024

Makes sense.
And type promotion when adding a scalar already works:

julia> Vec(1.0,2.0) + 1
<2 x Float64>[2.0, 3.0]

So it is better to handle Vec conversions explicitly.

@favba favba closed this as completed Sep 17, 2024
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