gleam-lang / language-tour

👩🏽‍💻 Learn Gleam in your browser
https://tour.gleam.run/
82 stars 62 forks source link

Misleading explanation of floats #20

Closed DrPhil closed 8 months ago

DrPhil commented 8 months ago

In chapter 0 lesson 5, "basics/floats":

Unlike many languages Gleam does not have a NaN or Infinity float value.

But Gleam does seem to have an Infinity (and also -Infinity) and NaN float value:

  let inf = 3.0e500
  io.debug(inf) // prints "Infinity"
  io.debug(0.0 -. inf) // prints "-Infinity"

  let nan = inf /. inf
  io.debug(nan) // prints "NaN"

  io.debug(float.compare(nan, 3.0)) // all comparisons with NaN prints "Gt"?

I don't know enough Gleam to know what the lesson should say instead - but I think this misleading comment should be removed in any case.

This is my first evening with Gleam. Sorry if this is already known - I tried searching and couldn't find any previous discussions about this at least. :)

lpil commented 8 months ago

Ah yes, good point. We should document the limitation of the JS target where these values do exist.

DrPhil commented 8 months ago

Ah! So it does depend on runtime! I thought I tested it on the BEAM when I tested it in the language-tour repo, but didn't know to look for the target = "javascript" line. Cool, that explains it - I was expecting the BEAM to crash. :)

DrPhil commented 8 months ago

\ I am also a bit surprised from a language design point of view that float overflow crashes. (It's expected from the BEAM though, so no blame on Gleam here.) Gleam seems to want to avoid the "let it crash" philosophy of the BEAM and have a more safe language. Might be too off-topic, so continuing this line of thought in the Discord. :)