Just a little bug in your code : you write 'other.x - other.x' and 'other.y - other.y' (instead of 'other.x - self.x' and 'other.y - self.y' in the .Float tag of your revised distance method :)
The version of Zig I'm using (0.14 dev) uses .int and .float (lowercase). I'm not sure when that breaking change was made but hopefully this helps some people.
I notice my object type returned as Point using @import("Point.zig") and point with @import("point.zig") and my file is just "point.zig". I was expecting an error loading a reference with wrong name and the object to identify himself with the name given inside the file. Feels too much Visual Basic for a language that don't want to acknowledge strings.
Good observation. I believe builtins like @sqrt that perform numeric operations are implemented using hardware-level instructions (where available) that make them extremely fast, and the types on which these operations perform are hard-wired, in this case floats only. In the std.math namespace you can find equivalent functions that do work with other types.
Just a little bug in your code : you write 'other.x - other.x' and 'other.y - other.y' (instead of 'other.x - self.x' and 'other.y - self.y' in the .Float tag of your revised distance method :)
Oh that was totally intentional to see if you guys are paying attention... lol Just kidding. I fixed it in the code repo. Thanks for the heads up!
second example blew my mind 😱 im very interested in learning zig now!
The version of Zig I'm using (0.14 dev) uses .int and .float (lowercase). I'm not sure when that breaking change was made but hopefully this helps some people.
Yes, during this 0.14 dev cycle, all standard library enum fields were normalized to lowercase. Good catch!
I notice my object type returned as Point using @import("Point.zig") and point with @import("point.zig") and my file is just "point.zig". I was expecting an error loading a reference with wrong name and the object to identify himself with the name given inside the file. Feels too much Visual Basic for a language that don't want to acknowledge strings.
Yeah, Zig's anonymous structs and their naming rules are indeed a bit strange. Takes getting used to them.
Maybe the devs could make the @sqrt builtin generic too? 🤔
Good observation. I believe builtins like @sqrt that perform numeric operations are implemented using hardware-level instructions (where available) that make them extremely fast, and the types on which these operations perform are hard-wired, in this case floats only. In the std.math namespace you can find equivalent functions that do work with other types.
you so slooooow… 🤦♂️
lol