#32bikeshed: allow comptime float to runtime int conversion

  • avatar~clovercommented · 2 years ago
    Author
    Owner

    currently, comptime floats that fit within valid 32-bit int sizes will coerce to integers. This means that the following calculation (0.5 + 1.5, which is 2.0) can coerce to int.

    let x: int = 0.5 + 1.5;
    @js("console").log(x);
    

    this issue is to discuss if this freedom should be removed or not. i want to keep this open for a while so that usage of the language decides this issue.


    Milestone: 0.3.0.

  • avatar~clover changed the status to Todo · 2 years ago
  • avatar~clovercommented · 2 years ago
    Author
    Owner

    at a glance, some people i've spoken to say this is a bad idea.

    i realize the rule to prevent this is to remove comptime_float, replace it with numeric_literal_int64 (and also add larger ints for bigint). all numbers that require fractional components would automatically coerce into a comptime known float, instead of a numeric literal. we can then change the printing of numeric_literal to be "integer literal", which can be an integer of any size.