---
title: "Rule 9.4: Built-in functions and the TypeShade extensions"
description: "Rule 9.4 of the TypeShade language design, in Built-in functions and the TypeShade extensions."
url: https://typeshade.dev/reference/rules/9-4/
language: en
---

# Rule 9.4

Chapter 9, Built-in functions and the TypeShade extensions Test

A `Math` member must lower to the WGSL builtin of the same meaning, and so must its free-function spelling where WGSL has a builtin of that name (`sqrt`, `max`; [Rule 9.9](https://typeshade.dev/reference/rules/9-9/) removed `pow`); a `Math` member with no WGSL builtin must be expanded into WGSL arithmetic, stays an ECMAScript name and has no free spelling; `Math.fround(x)` is `f32(x)`. A `Math` member takes the scalar arguments ECMAScript gives it; the vector form of the same operation is the WGSL name. A name a `const` binds to a `Math` member, by an object pattern over `Math` or by the member itself, must mean that member: a call of it is the member’s call, and a constant member is its inlined literal; it takes the member’s signatures, and no function value exists for it.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

## Rationale

see [Rule 2.4](https://typeshade.dev/reference/rules/2-4/).

## Derives from

`MATH_FN_ALIAS` and `MATH_EXPAND_ALIAS` in `src/compiler/ts/math-alias.ts`.

## How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

`surface-names.test.ts` and `src/compiler/ts/math-expand.test.ts`; the scalar arguments by `src/compiler/ts/math-scalar.test.ts` (change 0112); the bound name by `src/compiler/ts/math-binding.ts` and `math-binding.test.ts` (change 0113).

The files that verify it at commit af54ddad5, each at the first line that names the rule:

- [`src/compiler/ts/math-binding.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.test.ts#L1)
- [`src/compiler/ts/math-binding.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.ts#L1)
- [`src/compiler/ts/math-expand.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-expand.test.ts#L1)
- [`src/compiler/ts/math-scalar.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-scalar.test.ts#L1)
- [`src/core/spec-conformance/surface-names.test.ts:236`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/spec-conformance/surface-names.test.ts#L236)

## Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

- [§10 Builtins, casts and `discard`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#10-builtins-casts-and-discard)
- [§12 Module constants](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#12-module-constants)

## See also

- [Rule 9.3](https://typeshade.dev/reference/rules/9-3/) Test
- [Rule 9.5](https://typeshade.dev/reference/rules/9-5/) Test
- [Rule 2.4](https://typeshade.dev/reference/rules/2-4/)
- [Rule 9.9](https://typeshade.dev/reference/rules/9-9/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:1242`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L1242) (the design document)
- [`reqs/rules/RULE-0904.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0904.md) (its traceability item)
