Skip to content

Can't convert BigInt to Decimal without setting its value to 0 #142

Open
@James103

Description

@James103

Currently (latest break_eternity.js version as of 2023-01-07), attempting to convert a BigInt value to Decimal will return 0. Furthermore, a string that represents a number (generated by BigInt.toString()) will also return 0 if the number the string represents is at least 21024.

Console output with test cases:

new Decimal(String(2n**1022n)).toString() // 1
'4.494232837155819e307'

new Decimal(String(2n**1032n)).toString() // 2
'0'

new Decimal(1234n).toString() // 3
'0'

new Decimal(2n**1234n).toString() // 4
'0'
  1. Correct
  2. Incorrect; should be 21032 or about 4.602094e310
  3. Incorrect; should be 1234
  4. Incorrect; should be 21234 or about 2.958112e371

Discovered whilst writing migration code for an incremental game to convert various save data from BigInt values to their proper Decimals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions