added 3 characters in body
Source Link
Raghav Sood
  • 3.8k
  • 2
  • 7
  • 19

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 isisn't usable directly at the moment.

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 is usable directly at the moment.

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.

Source Link
Raghav Sood
  • 3.8k
  • 2
  • 7
  • 19

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 is usable directly at the moment.