8000 Numbers bigger than `1L << 53` loose lower bits when parsing by default parser using Scala.js · Issue #2311 · circe/circe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Numbers bigger than 1L << 53 loose lower bits when parsing by default parser using Scala.js #2311

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

Open
plokhotnyuk opened this issue Sep 17, 2024 · 3 comments

Comments

@plokhotnyuk
Copy link
Contributor

Script to reproduce:

//> using dep "io.circe::circe-core::0.14.10"
//> using dep "io.circe::circe-parser::0.14.10"
////> using dep "io.circe::circe-jawn::0.14.10"

import io.circe.Json
import io.circe.parser._
//import io.circe.jawn._

println(parse("[9007199254740993,9999999999999999999]").getOrElse(null))

Store it to script.js and use the following command to build with latest scala-cli:

scala-cli --power package --js --js-mode release script.sc --force -o script.js

Result of running with node:

[
  9007199254740992,
  10000000000000000000
]

Expected output:

[
  9007199254740993,
  9999999999999999999
]

Works fine with circe-jawn instead of circe-parser, or using JVMs or Scala Native.

@hamnis
Copy link
Collaborator
hamnis commented Sep 17, 2024

this is apparently using pure javascript JSON.parse, then converting after, so I guess standard javascript semantics should be expected.

@plokhotnyuk
Copy link
Contributor Author
plokhotnyuk commented Sep 17, 2024

this is apparently using pure javascript JSON.parse, then converting after, so I guess standard javascript semantics should be expected.

Then why println(Json.arr(Json.fromBigInt(BigInt("9223372036854775808")),Json.fromBigInt(BigInt("9999999999999999999"))).noSpaces) produces [9223372036854775808,9999999999999999999] without wrapping numbers by quotation marks?

Is it expected that the library cannot parse own output without loosing information when used with Scala.js?

@armanbilge
Copy link
Contributor

This problem is one of the reasons why I opened this issue.

My change was accepted, but only for the next major version.

Personally, I think we should backport this change as a bugfix, see #1941 (comment).

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

No branches or pull requests

3 participants
0