Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Fix sign error in BigInt::leftShift. #63

Closed
wants to merge 1 commit into from

Conversation

GeorgNeis
Copy link
Contributor

If y is negative, we need to divide by 2^(-y), i.e., multiply by 2^y.

If y is negative, we need to divide by 2^(-y), i.e., multiply by 2^y.
Copy link
Member

@littledan littledan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!

@@ -324,7 +322,7 @@
<h1>BigInt::signedRightShift (_x_, _y_)</h1>
<p>The abstract operation BigInt::signedRightShift with arguments _x_ and _y_ of type BigInt:</p>
<emu-alg>
1. Return ? BigInt::leftShift(_x_, -_y_).
1. Return BigInt::leftShift(_x_, -_y_).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Rather than eliminating the ? , better to replace it with ! because the definition of leftShift may throw for certain types (though we assert it won't). For example, for Number, it will call ToInt32, which could throw from ToNumber. That won't throw, since it's already a Number, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, but then the same should be done in the other definitions in 1.1 (that's 5 or 6 changes).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, really there's no way that this could possibly throw. I'll take your change here.

@@ -313,9 +313,7 @@
<h1>BigInt::leftShift (_x_, _y_)</h1>
<p>The abstract operation BigInt::leftShift with two arguments _x_ and _y_ of BigInt:</p>
<emu-alg>
1. If _y_ &lt; 0,
1. Return a BigInt representing _x_ divided by 2<sup>_y_</sup>, rounding down to the nearest integer, including for negative numbers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually like to keep the original, more wordy phrasing, since I believe we'll work towards a specification with no mathematical values and instead all numeric values in spec-land being either Numbers or BigInts (see #10). The small fraction in your spec text is not always representable as either. We could fix the issue more minimally by just inserting a - here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I need to read this when I have more time, but to answer your question: yes.

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

Successfully merging this pull request may close these issues.

2 participants