recently, I’ve been learning about the development of Ethereum smart contracts. I have a question about the following code; the result obtained by the “a” method is 4. This result is the same as my common sense understanding because, in the floating-point processing, the corresponding floating-point number will be intercepted when running. However, when I call the method “b”, the result is 5. I don't understand this result very well. Is it because the compiler has optimised during the compilation process to calculate the outcome directly and store it? Thanks a lot, guys.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Test {
uint constant c = 5;
function a() public pure returns(uint){
return c/2 + c/2;
}
function b() public pure returns(uint){
return 5/2 + 5/2;
}
}