pixie-lang / pixie

A small, fast, native lisp with "magical" powers
GNU General Public License v3.0
2.35k stars 124 forks source link

floating point literals for +-Inf, NaN ? #362

Open joshua-g opened 9 years ago

joshua-g commented 9 years ago

How do you (the language designers) feel about having a way to write literals for +- infinity and NaN? Currently you can generate these values via arithmetic. For instance, (/ 1.0 0) evaluates to positive infinity. Also, the literal 1e309 will evaluate to positive infinity. But inf doesn't have a canonical output representation in pixie. So if a program uses 1e400 and you try to compile it using pixie-vm -c, the compiled program will use the symbol inf instead of a float. That leads to a confusing error when you try to re-read the compiled file.

I think 0.Inf, -0.Inf, and 0.NaN are good ideas. cf. https://github.com/edn-format/edn/issues/2#issuecomment-31765748

Having +- infinity available could also simplify implementing or extending some algorithms. For instance, as initial values when computing maxes or mins. Or, if a function is already written in terms of some finite upper bound, it can often be trivially extended to work with no bound just by replacing the upper bound with +inf. E.g. (range 0.Inf)

halgari commented 9 years ago

I'm fine with this if we can get a PR

jmglov commented 8 years ago

I'll take a swing at this one. Looks relatively straight-forward.