←back to thread

611 points LorenDB | 1 comments | | HN request time: 0.225s | source
Show context
writebetterc ◴[] No.43908008[source]
Yes, Rust is better. Implicit numeric conversion is terrible. However, don't use atoi if you're writing C++ :-). The STL has conversion functions that will throw, so separate problem.
replies(3): >>43908176 #>>43910253 #>>43910408 #
titzer ◴[] No.43908176[source]
> Implicit numeric conversion is terrible.

It's bad if it alters values (e.g. rounding). Promotion from one number representation to another (as long as it preserves values) isn't bad. This is trickier than it might seem, but Virgil has a good take on this (https://github.com/titzer/virgil/blob/master/doc/tutorial/Nu...). Essentially, it only implicitly promotes values in ways that don't lose numeric information and thus are always reversible.

In the example, Virgil won't let you pass "1000.00" to an integer argument, but will let you pass "100" to the double argument.

replies(3): >>43908281 #>>43911977 #>>43913226 #
1. renox ◴[] No.43913226[source]
I disagree: when you use floats, you implicitly accept the precision loss/roundings that comes with using floats.. IMHO int to float implicit conversion is fine as long as you have explicit float to int conversion.