#55Implement TC39 Decimal as a first class primitive type

  • avatar~clovercommented · 2 years ago
    Author
    Owner

    See https://github.com/tc39/proposal-decimal. We can adopt this proposal better than the actual specification.

    The plan is to change numeric literals to be specifically designed as arbitrary precision numbers, essentially BigInt with a decimal point. I don't know if this type has an implementation anywhere, but we will find one. Arithmetic on numeric literals is exact.

    Then, when a coersion to a runtime type is needed, we put it into one of the following concrete numeric types:

    • "int" and "float", represented as JS Numbers
    • "bigint", represented as JS BigInt
    • "decimal", represented as JS Decimal, whatever the proposal API turns into.

    We probably should rename "numeric literal" to "comptime_number" to match how Zig has a named type for their version of this idea. #32 would be changed to split this into comptime_int and comptime_float or comptime_decimal.

    In the language, these are all just number literals. No classes or objects. Arithmetic operators work on them. + turns into a call to .add(), etc. This is only possible in our language since we require all types to be known for all operations (except opaque types, which will be overhauled). I imagine math work will be simple to write and fully reusable across number types, since the syntax is the same for each type (infer-based generics will greatly help, later proposal).


    Milestone: 0.3.0.

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

    People have given be very obvious flaws with my proposal for how comptime numbers should work. I will spend some time later figuring out a good design for how these literals can ergonomically work.