Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Shouldn't vec2 and vec3 understand // ?

Mod
Posts: 1,047

It seems that they do not. Thanks!

• Mod
Posts: 9,260

It does if you split them. Probably should the other way too.

``````function setup()
a=vec2(5,7)
print(a)
print(a/2)

print(a.x//2)
print(a.y//2)
end
``````
• Mod
Posts: 1,047

yes, split works because // works on numbers. since vectors do` deal with * and /, seems // should work as well. maybe.

• Posts: 632

what does the // operator do?

• Mod
Posts: 9,260

@piinthesky The // is a divide that returns an integer. 8 // 3 = 2.

• Posts: 2,239

All,

Interesting that a real number result divided by 1 with // gives a decimal number?

``````function setup()
--
output.clear()
print(7/2)
print(7//2)
print((7/2)//1)
end

``````

Noticed this before and have math.floor() on occasions to effect integer maths.

• Mod
Posts: 9,260

@Bri_G I’ve noticed that also on several occasions. Usually when I want integer results or anything else, I just use string format. That way I can get what I want to show, from integer to floating point with x digits past the decimal point.

• Posts: 509

You can extend the `vecX` types to enable this:

``````local m = getmetatable(vec2())
m["__idiv"] = function (c,q)
return vec2(c.x//q,c.y//q)
end
``````

and similarly for the others.