Skip to content

Instantly share code, notes, and snippets.

@DeityLamb
Created April 27, 2024 23:02
Show Gist options
  • Select an option

  • Save DeityLamb/3760a924029588e2a6ace07b89e321d9 to your computer and use it in GitHub Desktop.

Select an option

Save DeityLamb/3760a924029588e2a6ace07b89e321d9 to your computer and use it in GitHub Desktop.
The clamp function using only mathematical operators

(((x + min + |x - min|) / 2) + max - |((x + min + |x - min|) / 2) - max|) / 2

$\frac{(\frac{x + \min + |x - \min|}{2} + \max - |(\frac{x + \min + |x - \min|}{2} - \max|)}{2}$

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment