bool
Function
A numeric-to-boolean conversion tests whether a scalar is nonzero.
Compare examples
Zero converts to false; negative and positive values convert to true. A fractional value is true whenever it is nonzero.
Example 1bool(-1)
- Result
true
Example 2bool(0)
- Result
false
Example 3bool(0.25)
- Result
true
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it for turning numeric flags into conditions.
Inputs and limits
Use scalar input. This is a nonzero test, not rounding or a comparison with a midpoint.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Converts a numeric scalar to bool: true where x is not zero, spelled as the compare x != 0.
Syntax
declare function bool(): booldeclare function bool(x: number | bool): booldeclare function bool(x: number | bool): boolA number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.
type f32 = number & { readonly [f32Tag]?: true }
A number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.
Parameters
-
xoptionalnumber | bool
Return value
bool
Description
A bool argument is returned as it is.