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

Sign is printed twice when formatting a negative BigInt #4081

Closed
ryangoree opened this issue Aug 19, 2024 · 1 comment · Fixed by #4082
Closed

Sign is printed twice when formatting a negative BigInt #4081

ryangoree opened this issue Aug 19, 2024 · 1 comment · Fixed by #4082
Labels

Comments

@ryangoree
Copy link
Contributor

ryangoree commented Aug 19, 2024

Describe the Bug

If you format a negative BigInt instance, the sign (-) gets printed twice.

Steps to Reproduce

  1. Create a negative BigInt
    let int = BigInt::from(-1);
  2. Use console_log! macro to see it's formatted with 2 signs:
    console_log!("{}", int); // --1

Minimal test repo: https://github.com/ryangoree/js-sys-bigint-display-bug

Expected Behavior

The sign would be printed once (-1).

Actual Behavior

The sign is printed twice (--1).

@ryangoree ryangoree added the bug label Aug 19, 2024
@ryangoree
Copy link
Contributor Author

ryangoree commented Aug 19, 2024

Looks like the problem is here:

f.pad_integral(self >= &BigInt::from(0), "", &self.to_string_unchecked(10))

The docs for pad_integral state:

The str should not contain the sign for the integer, that will be added by this method.

However to_string_unchecked calls toString on the bigint which returns a string with the sign:

#[wasm_bindgen(method, js_name = toString)]
fn to_string_unchecked(this: &BigInt, radix: u8) -> String;

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

Successfully merging a pull request may close this issue.

1 participant