# Cast

`import { Cast } from "destack:math";`

Explicit lossy conversions between builtin integer types.

`as` between numeric types is lossless-only; these methods pick the lossy behavior explicitly.

```ds title="Cast"
export extension Cast {
    truncate<U: Integer>(): U;
    saturate<U: Integer>(): U;
    tryInto<U: Integer>(): U | undefined;
}
```

[language/library/src/math/cast.ds:16:31](https://github.com/destack-sh/destack/blob/main/language/library/src/math/cast.ds#L16-L31)

## Members

### `truncate<U: Integer>(): U`

Convert to `U`, keeping the low bits.

### `saturate<U: Integer>(): U`

Convert to `U`, clamping into the destination range.

### `tryInto<U: Integer>(): U | undefined`

Convert to `U` when the value is representable, or return `undefined`.
