> For the complete documentation index, see [llms.txt](https://docs.hology.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hology.app/zh-tw/shaders/typescript-shaders/math-functions.md).

# Math functions

Beyond the functions defined on the numeric types, there are other methods which works on most types. These are wrapping functions defined in the GLSL standard library. This page does not describe what each method does. Please see [GLSL documentation](https://www.shaderific.com/glsl-functions) to learn what they do if it is not clear by their signature.

Import functions like this:

```ts
import { dot, radians, saturate } from "@hology/core/shader-nodes"

```

### Trigonometry functions

```ts
radians<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
degrees<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sin<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
cos<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
tan<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
asin<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
acos<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
atan<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(yOverX: T): T
```

### Exponential functions

```ts
exp<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
log<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
exp2<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
log2<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sqrt<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
inversesqrt<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
pow<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T, y: T): T
```

### Geometric functions

```ts
length<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): FloatNode
normalize<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
```

### Common functions

```ts
abs<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
sign<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
floor<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
fract<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T
ceil<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T): T

mix<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(x: T, y: T, a: U): T

step<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(edge: U, x: T): T

smoothstep<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(edge0: U, edge1: U, x: T): T

clamp<
  T extends FloatNode | Vec2Node | Vec3Node | Vec4Node,
  U extends T | FloatNode
>(x: T, minVal: U, maxVal: U): T

saturate<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(a: T): T
```

### Vector functions

```ts
dot<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node>(x: T, y: T): FloatNode
```

### Matrix functions

```ts
inverse<T extends Mat2Node | Mat3Node | Mat4Node>(x: T): T
transpose<T extends Mat2Node | Mat3Node | Mat4Node>(x: T): T
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hology.app/zh-tw/shaders/typescript-shaders/math-functions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
