Naddiseo/dart-sprintf

Number bounds when compiled to javascript

Opened this issue · 2 comments

It seems number compiled to javascript (platform node/firefox/chrome) aren't using 53bit numbers for int anymore, so formatting with x or o or # now fail.

|%x|%X| -1 [E]                                                                                                                                     
  Expected: '|1fffffffffffff|1FFFFFFFFFFFFF|'
    Actual: '|ffffffff|FFFFFFFF|'
     Which: is different.
            Expected: |1fffffffff ...
              Actual: |ffffffff|F ...
                       ^
             Differ at offset 1

This was found while solving #18 and #12

@bergwerf, according to the int documentation ints are at least 53bits, but bitwise operations of 32bit on javascript platforms. I think I missed the bitwise part when I implemented the fix to #13.

On the one hand, "d"/"i" in C is a 32bit number, so it would make sense to clamp at that (And then introduce a BigInt formatter using %lld / %lli or something), on the other, this would be a rather large breaking change.

I think, the fix for #18/#12 can push the version to v4.1, and adding big ints can push the version to v5.
What do you think?

If you introduce a breaking change then indeed a major version increase would be appropriate (note that people who have ^4.0.0 in the dependencies will not automatically upgrade in that case).

Personally I wouldn't follow the C standard for formatted IO on this point, because integer size (in bytes) is not really a concept in Dart. As a developer I would expect that printf("%i", [2^50]) is sufficient to print any integer instance in Dart, just like in C where it would print any instance of a smaller integer type.