Elm Exactly

Basis entryBasics.clamp

A value of Basics. Its type is in Section C.3 Basics.

Static basis

var or con ↦ (σ,is)clamp ↦ (∀number. number→number→number  (∀number. →number,v)\begin{array}{|rcl|}\hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& (\sigma, \is)\\\hline \href{/standard/basis/Basics/clamp}{\kw{clamp}} {\ }& \mapsto {\ }& (\forall\mv{number}.\,\mv{number} \rightarrow \mv{number} \rightarrow \mv{number}\\ {\ }& {\ }& \phantom{(\forall\mv{number}.\,}{} \rightarrow \mv{number}, \isv)\\\hline\end{array}
Figure 38: Static VE\VE of ME0(Basics)\ME_0(\kw{Basics}): Constructors, Conversions, Comparison, Booleans and Integer Functions

Dynamic basis

var or con ↦ varityclamp ↦ basic value3\begin{array}{|rclc|}\hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& v {\qquad}& \arity\\\hline \href{/standard/basis/Basics/clamp}{\kw{clamp}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 3\\\hline\end{array}
Figure 45: Dynamic VE\VE of ME0(Basics)\ME_0(\kw{Basics})

Its APPLY

APPLY(clamp,x,y,z) = APPLY(min,z′,y)  where APPLY(max,z,x)={z′},\begin{array}{rcll} \APPLY(\kw{clamp},x,y,z) {\ }& = {\ }& \APPLY(\kw{min},z',y) {\quad}&\\ {\ }& {\ }& \quad\text{where}\ \APPLY(\kw{max},z,x)=\{z'\},&\end{array}
APPLY(clamp,v,v′,v′′) = {v}if APPLY(lt,v′′,v)={True} = {v′}if APPLY(gt,v′′,v′)={True} = {v′′}otherwise,\begin{array}{rcll} \APPLY(\kw{clamp},v,v',v'') {\ }& = {\ }& \{v\} {\quad}& \text{if}\ \APPLY(\kw{lt},v'',v)=\{\kw{True}\}\\ {\ }& = {\ }& \{v'\} {\quad}& \text{if}\ \APPLY(\kw{gt},v'',v')=\{\kw{True}\}\\ {\ }& = {\ }& \{v''\} {\quad}& \text{otherwise}, \end{array}
Read it in its chapter·Permanent address: /standard/basis/Basics/clamp

Tests (3)

  • elm-core / BasicsClampTest
    `clamp 5 10` returns the lower bound for 3, the value itself for 7 and the upper bound for 15, and `clamp 1.0 5.0` leaves 3.5 unchanged.
  • elm-core / CoreIssue1080ClampNanTest
    `clamp -100 100` of NaN returns NaN.
  • elm-core / StandardA49ClampTest
    `clamp lo hi x`: at Float it is `min (max x lo) hi`, with the IEEE 754 `maximum` and `minimum` that propagate NaN and order `-0` below `+0`; at Int it is the text of elm/core.

Discussions

Discuss this basis entry·Search the discussions on GitHub

Discussions are on GitHub; one about this basis entry has [b:Basics.clamp] in its title.

A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.