Constrains a value between a lower and upper bound. Use this tag when working with a clamp() function in the languages that support it. Not to be confused with CLAMP Toolkit (Clinical Language Annotation, Modeling, and Processing).
In computer terms, to clamp a value is to make sure that it lies between some maximum and minimum values. If it’s greater than the max value, then it is replaced by the max, etc.
Clamp documentation links based on native language support:
.NET -> https://learn.microsoft.com/en-us/dotnet/api/system.math.clamp?view=netcore-3.1
C++ -> https://en.cppreference.com/w/cpp/algorithm/clamp
CSS -> MDN ; CSS Values
R -> (raster package) https://www.rdocumentation.org/packages/raster/versions/3.3-13/topics/clamp
Ruby -> (Comparable package) https://ruby-doc.org/core-2.7.0/Comparable.html#method-i-clamp
Rust -> https://docs.rs/num/0.2.1/num/fn.clamp.html
Many languages, such as C, Haskell, Java, JavaScript, PHP, Python, and Raku (Perl 6) do not have a native clamp implementation. Workarounds, custom implementations, or native feature extensions for a given language can typically be found by searching for "clamp in " here on Stack Overflow.
Not to be confused with the CLAMP Toolkit (Clinical Language Annotation, Modeling, and Processing).