Since solidity has not float types, how does it computes products between "floating point numbers" and ints?
The floating point value never enters the evm. Units such as ether
and seconds
are only for convenience, and will be converted away by the compiler.
For a simple test contract:
pragma solidity ^0.4.24;
contract Test {
uint256 public etherValue;
constructor() {
etherValue = 0.1 ether;
}
}
We get the following (relevant) AST for the assignment:
{
"attributes" :
{
"argumentTypes" : null,
"hexvalue" : "302e31",
"isConstant" : false,
"isLValue" : false,
"isPure" : true,
"lValueRequested" : false,
"subdenomination" : "ether",
"token" : "number",
"type" : "int_const 100000000000000000",
"value" : "0.1"
},
"id" : 7,
"name" : "Literal",
"src" : "103:9:0"
}
As you can see, 0.1 ether
has been converted to 100000000000000000
(1 followed by 17 zeroes)
Finally, this produces the following EVM op codes:
PUSH 0x16345785D8A0000
0x16345785D8A0000
being the hex representation of 100000000000000000
Additionally, solidity internally does have rudimentary support for float values, although it isn't usable directly at the moment.
-
1