-
-
Notifications
You must be signed in to change notification settings - Fork 6
nanvm: format bigint string coercion as decimal #1709
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb01c96
nanvm: format bigint string coercion as decimal
sergey-shandar d93c80c
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar da2e908
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 9757459
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 61bddaa
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar b189559
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 7e7fe29
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar ac3719f
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 32da59e
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 0d9e478
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 3e758b4
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar d346335
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sergey-shandar 890f7ca
Merge branch 'main' into codex/fix-open-issue-in-todo-files
sasha-gil 237a0c5
nanvm: fix bigint Display to use sign(), drop stale README
sasha-gil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - nanvm: bigint string coercion now produces JavaScript-compatible decimal text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use crate::{ | ||
| common::sized_index::SizedIndex, | ||
| sign::Sign, | ||
| vm::{BigInt, IContainer, IVm}, | ||
| }; | ||
| use core::fmt::{Display, Formatter, Result, Write}; | ||
|
|
||
| const DECIMAL_BASE: u64 = 10_000_000_000_000_000_000; | ||
|
|
||
| impl<A: IVm> Display for BigInt<A> { | ||
| fn fmt(&self, f: &mut Formatter<'_>) -> Result { | ||
| if self.is_zero() { | ||
| return f.write_char('0'); | ||
| } | ||
| if self.sign() == Sign::Negative { | ||
| f.write_char('-')?; | ||
| } | ||
|
|
||
| let items = self.0.items(); | ||
| let mut words: Vec<u64> = (0..items.length()).map(|i| items[i]).collect(); | ||
| let mut groups = Vec::new(); | ||
| while !words.is_empty() { | ||
| let mut remainder = 0u128; | ||
| for word in words.iter_mut().rev() { | ||
| let dividend = (remainder << 64) | *word as u128; | ||
| *word = (dividend / DECIMAL_BASE as u128) as u64; | ||
| remainder = dividend % DECIMAL_BASE as u128; | ||
| } | ||
| groups.push(remainder as u64); | ||
| while words.last() == Some(&0) { | ||
| words.pop(); | ||
| } | ||
| } | ||
|
|
||
| write!(f, "{}", groups.pop().unwrap())?; | ||
| for group in groups.iter().rev() { | ||
| write!(f, "{group:019}")?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ mod add; | |
| mod cmp; | ||
| mod debug; | ||
| mod default; | ||
| mod display; | ||
| mod from; | ||
| mod index; | ||
| mod mul; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.