Clamps the given value to the [0, 1] range.

Type signature

(x: number) => number

Examples

clampNormal(0.5);
// ⇒ 0.5
Try in REPL
clampNormal(-0.5);
// ⇒ 0
Try in REPL
clampNormal(1.5);
// ⇒ 1
Try in REPL

Questions

  • How to clamp value to be in 0 to 1 inclusive range?
  • How to clamp value to be in the normal range?

TypeScript sourceJavaScript source