Elm Exactly

Basis entryBasics.truncate

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

Static basis

var or con ↦ (σ,is)ceiling, truncate ↦ (Float→Int,v)\begin{array}{|rcl|}\hline \var\ \text{or}\ \con {\ }& \mapsto {\ }& (\sigma, \is)\\\hline \href{/standard/basis/Basics/ceiling}{\kw{ceiling}},\ \href{/standard/basis/Basics/truncate}{\kw{truncate}} {\ }& \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(truncate,x) = {sat(trunc(x))}if x∈Fltfin\begin{array}{rcll} \APPLY(\kw{truncate},x) {\ }& = {\ }& \{\dbsat(\dbtrunc(x))\} {\quad}& \text{if}\ x\in\effFltFin\end{array}
Figure 53: APPLY\APPLY on Conversions
Read it in its chapter·Permanent address: /standard/basis/Basics/truncate

Tests (4)

  • 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 / FloatTruncateTest
    `truncate` rounds a Float toward zero: 2.7 and 2.3 give 2, and -2.3 and -2.7 give -2.
  • elm-core / StandardA44TruncateWideTest
    `truncate` of a Float beyond 32 bits does not wrap.
  • elm-core / TruncateToIntTest
    `truncate` rounds a `Float` towards zero: 2.7 gives 2 and -2.7 gives -2.

Discussions

Discuss this basis entry·Search the discussions on GitHub

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