Are div and / meant to be the same?
jdf-id-au opened this issue · 3 comments
Thanks for your prolific and amazing contributions.
I don't understand the following type mismatch when using /
vs div
:
import vmath
let a = uvec2(10, 10)
a/2 # type mismatch
a.div(2) # uvec2(5,5) == type GVec2[system.uint32]
Sorry I couldn't work it out by myself, they both seem to use genOp.
Interestingly I get the same problem the other way around with vec2
:
import vmath
let b = vec2(0.3, 1)
b/0.3 # vec2(1.0, 3.33...) == type GVec2[system.float32]
b.div(0.3) # type mismatch
I don't see a problem here. I think the confusion comes from the fast that a.div(2)
returns some thing and needs to be discarded or saved. Same from the b/0.3
case. Also I would write that as a div 2
as that is more common as div
is acting like an integer version of the /
operator.
This is the test I ended up using that show the correct and expected behavior:
block:
let a = uvec2(10, 10)
var b: UVec2
when compiles(b = a / 2): doAssert false # type mismatch
b = a div 2
block:
let a = vec2(10, 10)
var b: Vec2
b = a / 2
when compiles(b = a div 2): doAssert false # type mismatch
Feel free to reopen if I missed some thing.
Thanks for feedback, maybe my type-sloppiness from years of python and clojure is to blame :)