Open rotu opened 2 years ago
I got same result in C lang: https://wandbox.org/permlink/QzZiIKrp1Tv1msxq
It seems converting int to float result in larger value because it is lossy convertion.
Converting float value larger than int.high result in negative value because it is undefined behavior?
Maybe Nim should throw OverflowDefect
when converting float value larger than int.high
.
Yeah, it's UB since the floating point is out of range of an int. I think an OverflowDefect
would be appropriate. I'm also very surprised that trying to convert Inf
and NaN
throws an error at compile time but not at runtime.
Converting a large positive floating point number to an integer can result in a large negative integer.
Example
https://play.nim-lang.org/#ix=45QL
Current Output
please check whether the problem still exists in git head before posting, see rebuilding the compiler.
Expected Output
something like
or
Additional Information