For example, if I convert the float type 2.0000000000 to int, the underlying storage should be 1.999999999999999. There is a precision limit, so when I convert this number to int, I think it will become 1 (the decimal part is discarded)
But after testing several languages, they are still correct (php, java, go, js)
php:
js:
go:
java:
滿天的星座2017-06-12 09:21:20
2.0
can be accurately expressed by floating point numbers. There should be no problems with this number
我想大声告诉你2017-06-12 09:21:20
Decimals are stored in scientific notation, not 1.999999..., they are processed during the forced transfer, not directly converted to a type
漂亮男人2017-06-12 09:21:20
Generally speaking, converting low precision to high precision, such as int->float, when converting high precision to low precision, you will lose precision, and the data results may become very surprising.
世界只因有你2017-06-12 09:21:20
It has no practical significance. If it really works like you think, the person who designed this language will definitely take it into consideration
Detailed understanding requires certain assembly principles, so don’t get too carried away