StringFromFloatJsFormatTest
`String.fromFloat` writes numbers as JavaScript's `Number.prototype.toString` does: plain digits for magnitudes from 1e-6 up to but not including 1e21, and exponent form (`1e+21`, `1.5e+300`, `1e-7`, `1.25e-7`) outside that range. The ten values are converted with `List.map String.fromFloat` and joined with commas, so one line checks them all. Among them, 1e9 must print as `1000000000` rather than `1e+09`, and a value with a fractional part, `123456789.125`, keeps every digit.
Results
elm-0.19.1
passran in 39 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. formatted: "1000000000,-1000000000,100000000000000000000,1e+21,1.5e+300,0.000001,1e-7,1.25e-7,123456789.125,0.1"
elm-0.19.2
passran in 46 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. formatted: "1000000000,-1000000000,100000000000000000000,1e+21,1.5e+300,0.000001,1e-7,1.25e-7,123456789.125,0.1"
elm-0.19.3
passran in 51 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. formatted: "1000000000,-1000000000,100000000000000000000,1e+21,1.5e+300,0.000001,1e-7,1.25e-7,123456789.125,0.1"
lamdera-1.5.0
passran in 44 msOutput
formatted: "1000000000,-1000000000,100000000000000000000,1e+21,1.5e+300,0.000001,1e-7,1.25e-7,123456789.125,0.1"
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-core/StringFromFloatJsFormatTest] in its title.
Source
The -- CHECK: lines give the expected output.
module StringFromFloatJsFormatTest exposing (main)
{-| `String.fromFloat` writes numbers as JavaScript's `Number.prototype.toString` does:
plain digits for magnitudes from 1e-6 up to but not including 1e21, and exponent form
(`1e+21`, `1.5e+300`, `1e-7`, `1.25e-7`) outside that range.
The ten values are converted with `List.map String.fromFloat` and joined with commas, so
one line checks them all. Among them, 1e9 must print as `1000000000` rather than `1e+09`,
and a value with a fractional part, `123456789.125`, keeps every digit.
-}
-- CHECK: formatted: "1000000000,-1000000000,100000000000000000000,1e+21,1.5e+300,0.000001,1e-7,1.25e-7,123456789.125,0.1"
import Html exposing (text)
main =
let
_ =
Debug.log "formatted"
([ 1.0e9, -1.0e9, 1.0e20, 1.0e21, 1.5e300, 0.000001, 1.0e-7, 1.25e-7, 123456789.125, 0.1 ]
|> List.map String.fromFloat
|> String.join ","
)
in
text "done"