Elm Exactly
Results / elm-bytes /

DecodeFloat32BETest

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
`Bytes.Decode.float32 BE` reads back a 32-bit big-endian float written by `Bytes.Encode.float32 BE`.

The value `3.14159` does not survive 32-bit precision exactly, so the test rounds the decoded value to two decimal places and expects `3.14`.

Results

elm-0.19.1

passran in 45 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
DecodeFloat32BETest: 3.14

elm-0.19.2

passran in 68 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
DecodeFloat32BETest: 3.14

elm-0.19.3

passran in 51 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
DecodeFloat32BETest: 3.14

lamdera-1.5.0

passran in 43 ms
Output
DecodeFloat32BETest: 3.14

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/DecodeFloat32BETest] in its title.

Source

The -- CHECK: lines give the expected output.

module DecodeFloat32BETest exposing (main)
{-| `Bytes.Decode.float32 BE` reads back a 32-bit big-endian float written by `Bytes.Encode.float32 BE`.
The value `3.14159` does not survive 32-bit precision exactly, so the test rounds the decoded value to two decimal places and expects `3.14`.
-}
-- CHECK: DecodeFloat32BETest: 3.14
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
main =
let
bytes =
E.encode (E.float32 BE 3.14159)
result =
D.decode (D.float32 BE) bytes
|> Maybe.withDefault 0.0
-- Float32 has limited precision
rounded =
toFloat (round (result * 100)) / 100
_ =
Debug.log "DecodeFloat32BETest" rounded
in
text (String.fromFloat rounded)