Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ The <dfn noexport>ceiling expression</dfn> is defined over real numbers |x|:

* &lceil;|x|&rceil; = |k|, where |k| is the unique integer such that |k|-1 &lt; |x| &le; |k|

The <dfn noexport>truncate</dfn> function is defined over real numbers |x|:

* truncate(|x|) = &lfloor;|x|&rfloor; if |x| &ge; 0, and &lceil;|x|&rceil; if |x| &lt; 0.

The <dfn noexport>roundUp</dfn> function is defined for positive integers |k| and |n| as:

* roundUp(|k|, |n|) = &lceil;|n| &div; |k|&rceil; &times; |k|
Expand Down Expand Up @@ -4574,11 +4578,37 @@ See [[#sync-builtin-functions]].
<tr algorithm="signed integer division">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [SIGNEDINTEGRAL]
<td>|e1| `/` |e2| : |T|
<td>Signed integer division. [=Component-wise=] when |T| is a vector. (OpSDiv)
<td>Signed integer division. [=Component-wise=] when |T| is a vector.

In the scalar case, evaluates to:
* |e1|, when |e2| is zero.
* |e1|, when |e1| is the most negative value in |T|, and |e2| is -1.
* [=truncate=](|x|) otherwise, where |x| is the
real-valued quotient |e1|&nbsp;&div;&nbsp;|e2|.

Note:
The need to ensure truncation behaviour may require an implementation
to perform more operations than when computing an unsigned division.
Use unsigned division when both operands are known to have the same sign.

<!--
where MINIT = most negative value in |T|
where Divisor = select(e2, 1, (e2==0) | ((e1 == MININT) & (e2 == -1)))
result is truncate(e1/Divisor)
-->

<tr algorithm="unsigned integer division">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [UNSIGNEDINTEGRAL]
<td>|e1| `/` |e2| : |T|
<td>Unsigned integer division. [=Component-wise=] when |T| is a vector. (OpUDiv)
<td>Unsigned integer division. [=Component-wise=] when |T| is a vector.

In the scalar case, evaluates to:
* |e1|, when |e2| is zero.
* Otherwise, the integer |q| such that
|e1|&nbsp;=&nbsp;|q|&nbsp;&times;&nbsp;|e2|&nbsp;+&nbsp;|r|,
where 0 &le; |r| &lt; |e2|.

(OpUDiv, with OpSelect to avoid division by zero)
<tr algorithm="floating point division">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [FLOATING]
<td>|e1| `/` |e2| : |T|
Expand All @@ -4587,11 +4617,39 @@ See [[#sync-builtin-functions]].
<tr algorithm="signed integer remainder">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [SIGNEDINTEGRAL]
<td>|e1| `%` |e2| : |T|
<td>Signed integer remainder. [=Component-wise=] when |T| is a vector. (OpSRem)
<tr algorithm="unsigned integer modulus">
<td>Signed integer remainder. [=Component-wise=] when |T| is a vector.

In the scalar case, evaluates |e1| and |e2| once, and evaluates to:
* 0, when |e2| is zero.
* 0, when |e1| is the most negative value in |T|, and |e2| is -1.
* Otherwise, |e1|&nbsp;-&nbsp;[=truncate=](|e1|&nbsp;&div;&nbsp;|e2|)&nbsp;&times;&nbsp;|e2|
where the quotient is computed as a real value.

Note:
When non-zero, the result has the same sign as |e1|.

Note:
The need to ensure consistent behaviour may require an implementation
to perform more operations than when computing an unsigned remainder.

<!--
where MINIT = most negative value in |T|
where Divisor = select(e2, 1, (e2==0) | ((e1 == MININT) & (e2 == -1)))
result is e1 - truncate(e1/Divisor) * Divisor
-->

<tr algorithm="unsigned integer remainder">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [UNSIGNEDINTEGRAL]
<td>|e1| `%` |e2| : |T|
<td>Unsigned integer remainder. [=Component-wise=] when |T| is a vector. (OpUMod)
<td>Unsigned integer remainder. [=Component-wise=] when |T| is a vector.

In the scalar case, evaluates to:
* 0, when |e2| is zero.
* Otherwise, the integer |r| such that
|e1|&nbsp;=&nbsp;|q|&nbsp;&times;&nbsp;|e2|&nbsp;+&nbsp;|r|,
where |q| is an integer and 0 &le; |r| &lt; |e2|.

(OpUMod, with OpSelect to avoid division by zero)
<tr algorithm="floating point remainder">
<td>|e1| : |T|<br>|e2| : |T|<br>|T| is [FLOATING]
<td>|e1| `%` |e2| : |T|
Expand Down