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

It seems that they do not. Thanks!

Comments

  • dave1707dave1707 Mod
    Posts: 8,671

    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.

  • Posts: 565

    what does the // operator do?

  • dave1707dave1707 Mod
    Posts: 8,671

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

  • Posts: 1,865

    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.

  • dave1707dave1707 Mod
    Posts: 8,671

    @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: 498

    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.

  • SimeonSimeon Admin Mod
    Posts: 5,420

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

Sign In or Register to comment.