---
title: "sub"
description: "The first value minus the second."
group: "space"
groupTitle: "Shapes, frames & warps"
categoryId: "math"
categorySlug: "math"
categoryTitle: "Math"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/math.ts#L56"
---

# sub

The first value minus the second.

```ts
sub(a: Val, b: Val): Expr
```

Import `math` from `shaders/std` and use `math.sub`.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `a` | `Val` |  |
| `b` | `Val` |  |

## Example

```ts
const outside = sub(1, coverage) // flip a 0..1 mask
```

## See also

- [`add`](/docs/primitives/math/add) — The sum of two values.
- [`neg`](/docs/primitives/math/neg) — The value with its sign flipped.

## Used by

[Aurora](/docs/components/aurora), [BrushedMetal](/docs/components/brushedmetal), [CarbonFiber](/docs/components/carbonfiber), [Chrome](/docs/components/chrome), [Crystal](/docs/components/crystal), [FlowingGradient](/docs/components/flowinggradient), [Frost](/docs/components/frost), [Goo](/docs/components/goo), [Heatmap](/docs/components/heatmap), [Hologram](/docs/components/hologram), [Holographic](/docs/components/holographic), [Irradiance](/docs/components/irradiance), [LiquidMetal](/docs/components/liquidmetal), [MeshGradient](/docs/components/meshgradient), [Nebula](/docs/components/nebula), [Obsidian](/docs/components/obsidian), [PixelThrow](/docs/components/pixelthrow), [Plastic](/docs/components/plastic), [Prism](/docs/components/prism), [ReactionDiffusion](/docs/components/reactiondiffusion), [Satin](/docs/components/satin), [StudioBackground](/docs/components/studiobackground), [Voxels](/docs/components/voxels), [Water](/docs/components/water), [Waveform](/docs/components/waveform)