Results 1 to 3 of 3

Thread: evaluating side-effetcs and Logical && and || for vectors

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    1

    evaluating side-effetcs and Logical && and || for vectors

    Since logical && and || need to be evaluated component-wise for vectors, are c[0] and c[2] the only components that need to be evaluated because only b[0] and b[2] were nonzero? What if the RHS of && is a complicated expression(e.g. b&&foo())? Is the statement about evaluating the RHS only when LHS is equal/unequal to 0 meant only apply when both operands are scalar?

    int4 a;
    int4 b=(int4)(1,0,1,0);
    int4 c=(int4)(10,10,10,10);
    a=(b&&--c);
    //a is (-1,0,-1,0) but should c be now (9,10,9,10) or (9,9,9,9)?

    The 1.0 spec states:
    "And (&&) will only evaluate the right hand operand if the left hand operand compares unequal to 0. Or (||) will only evaluate the right hand operand if the left hand operand compares equal to 0. For built-in vector types, the operators are applied component-wise"

  2. #2
    Senior Member
    Join Date
    Sep 2002
    Location
    Santa Clara
    Posts
    105

    Re: evaluating side-effetcs and Logical && and || for vectors

    Operations on vectors are applied component-wise.

    In the example you give below, the logical && will be applied as follows:

    a.x = b.x && c.x;
    a.y = b.y && c.y;
    a.z = b.z && c.z;
    a.w = b.w && c.w;

    The spec states that "And (&&) will only evaluate the right hand operand if the left hand operand compares unequal to 0.". For the example above, c.x is evaluated only if b.x is not zero. Note that the left hand and right hand operands can be expressions. The expression will result in a scalar value. The statement in the spec is for evaluating the RHS only when LHS is equal/unequal to 0 for scalars.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    6

    Re: evaluating side-effetcs and Logical && and || for vectors

    RHS can have subeffect that cannot be interpreted as component wise. For example:
    Code :
     a = (b && (func(c))); // function call
     a = (b && (puts("a"), c)); // comma operator
    How to interpret it?

Similar Threads

  1. Multitexturing && Texture With Alpha Channel problem....
    By Rubbio in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 04-20-2009, 06:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •