ModularM
Modular2y ago
4 replies
Firas

RayTracing example - __add__ method (dunder methods)

In the RayTracing example, in the first class implementation Vec3f, in the dunder methods (add sub ...etc)
the implementation is like this:
fn add(self, other: Vec3f) -> Vec3f:
return self.data + other.data
this return data, and it's type is SIMD,
shouldn't it be:
fn add(self, other: Vec3f) -> Vec3f:
return Vec3f(self.data + other.data)
??

I tried both and both compiled and worked.
But why the the first implementation (the one in the example) work!!
the function needs to return Vec3f but it returns SIMD !!
Was this page helpful?