Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can d3-array also support BigInt numbers? #280

Open
tx0c opened this issue Mar 6, 2024 · 2 comments
Open

can d3-array also support BigInt numbers? #280

tx0c opened this issue Mar 6, 2024 · 2 comments

Comments

@tx0c
Copy link

tx0c commented Mar 6, 2024

some like d3.ascending d3.descending have no problems, some are not:

const bigints = [ 1n, 2n, 3n, -300n ];

bigints.sort(d3.descending); // okay
d3.sum(bigints); // error
file:///path/to/node_modules/d3-array/src/sum.js:5
      if (value = +value) {
                  ^

TypeError: Cannot convert a BigInt value to a number
    at Module.sum (file:///path/to/tmp/node_modules/d3-array/src/sum.js:5:19)
    at file:///path/to/tmp/xxx.mjs:67:6
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v21.2.0
@Fil
Copy link
Member

Fil commented Mar 6, 2024

try d3.sum(bigints, Number)?

@mbostock
Copy link
Member

mbostock commented Mar 7, 2024

In general, no. We’d need a d3.bigsum if we wanted to be accurate with respective to BigInt. You can coerce to Number as @Fil suggested if you don’t actually need an exact answer though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants