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 // ?

in Suggestions Posts: 1,350

It seems that they do not. Thanks!


  • dave1707dave1707 Mod
    Posts: 9,989

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

    function setup()
  • Posts: 1,350

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

  • what does the // operator do?

  • dave1707dave1707 Mod
    Posts: 9,989

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

  • Posts: 2,691


    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.

  • dave1707dave1707 Mod
    Posts: 9,989

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

    and similarly for the others.

  • SimeonSimeon Admin Mod
    Posts: 5,778

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

Sign In or Register to comment.