Elm Exactly
Results / elm-bytes /

RoundtripFloat64Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Floats survive a big-endian `float64` encode and decode with elm/bytes exactly.

The values 0, 1, -1, 3.141592653589793 and the largest finite double,
1.7976931348623157e308, are each round-tripped and compared with `==`. The
program logs `True` only if all of them come back unchanged.

Results

elm-0.19.1

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

elm-0.19.2

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

elm-0.19.3

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

lamdera-1.5.0

passran in 56 ms
Output
RoundtripFloat64Test: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module RoundtripFloat64Test exposing (main)
{-| Floats survive a big-endian `float64` encode and decode with elm/bytes exactly.
The values 0, 1, -1, 3.141592653589793 and the largest finite double,
1.7976931348623157e308, are each round-tripped and compared with `==`. The
program logs `True` only if all of them come back unchanged.
-}
-- CHECK: RoundtripFloat64Test: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
roundtrip : Float -> Bool
roundtrip n =
D.decode (D.float64 BE) (E.encode (E.float64 BE n)) == Just n
main =
let
allPass =
roundtrip 0.0
&& roundtrip 1.0
&& roundtrip -1.0
&& roundtrip 3.141592653589793
&& roundtrip 1.7976931348623157e308
_ =
Debug.log "RoundtripFloat64Test" allPass
in
text (if allPass then "True" else "False")