4 ms·
When I create my own programming language, the syntax for float literals will be: ≈3.14159
by rbonvall 5y ago
When I create my own programming language, the syntax for float literals will be:
≈3.14159
- enriquto 5y agoThis does not make sense: floating point numbers are not really "approximate". For example, small integer arithmetic using floats is guaranteed to be exact. Your language would be very confusing for this common use case.
- lifthrasiir 5y agoThis does kinda exist in Scheme and Racket: > (/ 1 10) 1/10 > (exact? (/ 1 10)) 1/10 > (/ 1.0 10.0) 0.1 > (exact? (/ 1.0 10.0)) #f > (/ #e1.0 #e10.0) ; #e for "exact" 1/10 > (/ #i1 #i10) ; #i for "inexact" 0.1 As mentioned in HN before [1], Pyret (which has the same origin as Racket) went further and made the exact literal (now "Exactnum") default, so the inexact literal (now "Roughnum") always requires a preceding `~`. [1] https://news.ycombinator.com/item?id=28263486 https://news.ycombinator.com/item?id=28263486