Shouldn't vec2 and vec3 understand // ?

It seems that they do not. Thanks!

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

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

what does the // operator do?

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

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.

@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.

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.

I’ve made a note to add native integer divide operator support for the vec types