---
title: "bool: shader function examples, uses and input limits"
description: "A numeric-to-boolean conversion tests whether a scalar is nonzero. Use it for turning numeric flags into conditions. Use scalar input."
url: https://typeshade.dev/reference/functions/bool/
language: en
---

# `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 1`bool(-1)`**

**Result**

`true`

**Example 2`bool(0)`**

**Result**

`false`

**Example 3`bool(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](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`select`](https://typeshade.dev/reference/functions/select/)
- [`i32`](https://typeshade.dev/reference/functions/i32/)
- [`u32`](https://typeshade.dev/reference/functions/u32/)

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

```ts
declare function bool(): bool
declare function bool(x: number | bool): bool
declare function bool(x: number | bool): bool
```

A `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](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

## Parameters

- `x` optional `number | bool`

## Return value

`bool`

## Description

A `bool` argument is returned as it is.

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [`bool()` in `typeshade/core/ir`](https://typeshade.dev/api/bool/)
