Elm Exactly

Basis entryBasics.round

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

Static basis

var or con ↦ (σ,is)round, floor ↦ (Float→Int,v)\begin{array}{|rcl|}\hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& (\sigma, \is)\\\hline \href{/standard/basis/Basics/round}{\kw{round}},\ \href{/standard/basis/Basics/floor}{\kw{floor}} {\ }& \mapsto {\ }& (\tFloat \rightarrow \tInt, \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 ↦ varitytoFloat, round, floor, ceiling, truncate ↦ basic value1\begin{array}{|rclc|}\hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& v {\qquad}& \arity\\\hline \href{/standard/basis/Basics/toFloat}{\kw{toFloat}},\ \href{/standard/basis/Basics/round}{\kw{round}},\ \href{/standard/basis/Basics/floor}{\kw{floor}},\ \href{/standard/basis/Basics/ceiling}{\kw{ceiling}},\ \href{/standard/basis/Basics/truncate}{\kw{truncate}} {\ }& \mapsto {\ }& \text{basic value} {\qquad}& 1\\\hline\end{array}
Figure 45: Dynamic VE\VE of ME0(Basics)\ME_0(\kw{Basics})

Its APPLY

APPLY(round,x) = {sat(⌊x+12⌋)}if x∈Fltfin\begin{array}{rcll} \APPLY(\kw{round},x) {\ }& = {\ }& \{\dbsat(\lfloor x+\tfrac{1}{2}\rfloor)\} {\quad}& \text{if}\ x\in\effFltFin\end{array}
Figure 53: APPLY\APPLY on Conversions
Read it in its chapter·Permanent address: /standard/basis/Basics/round

Tests (5)

  • elm / FloatEdgeTest
    Float edge cases: `round` on halves, NaN in equality, `min` and `compare`, `truncate` of NaN, and an Int power beyond 2^32.
  • elm-core / FloatRoundTest
    `round` rounds a Float to the nearest Int, with halves rounded up: 2.5 gives 3 and 3.5 gives 4.
  • elm-core / RoundToIntTest
    Checks that `round` converts a `Float` to the nearest `Int`: `2.7` gives `3`, `2.3` gives `2` and `-2.7` gives `-3`.
  • elm-core / StandardA44RoundNonFiniteTest
    `round`, `floor` and `ceiling` of NaN are `0`, and of an infinity an Int.
  • elm-core / StandardA45IntNegativeZeroTest
    Int has one zero: no Int operation gives a negative zero.

Discussions

Discuss this basis entry·Search the discussions on GitHub

Discussions are on GitHub; one about this basis entry has [b:Basics.round] 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.