Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Issue 1205363003: Add tests for gcd, modInverse and modPow that also run on dart2js. (Closed)

Created:
5 years, 6 months ago by Lasse Reichstein Nielsen
Modified:
5 years, 6 months ago
Reviewers:
regis, Søren Gjesse
CC:
reviews_dartlang.org, vm-dev_dartlang.org, srdjan
Base URL:
https://github.com/dart-lang/sdk.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Add tests for gcd, modInverse and modPow that also run on dart2js. R=regis@google.com, sgjesse@google.com Committed: https://github.com/dart-lang/sdk/commit/3a0edfba72e27781e98f5debfafc5f01450bd423

Patch Set 1 #

Total comments: 2

Patch Set 2 : Fix another bug. #

Total comments: 2

Patch Set 3 : Fix status file names. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+220 lines, -7 lines) Patch
M runtime/lib/bigint.dart View 1 2 4 chunks +10 lines, -7 lines 0 comments Download
M tests/corelib/corelib.status View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
A tests/corelib/int_modulo_arith_test.dart View 1 1 chunk +207 lines, -0 lines 0 comments Download

Messages

Total messages: 7 (1 generated)
Lasse Reichstein Nielsen
5 years, 6 months ago (2015-06-25 12:59:52 UTC) #2
regis
lgtm Thanks for writing this test. https://codereview.chromium.org/1205363003/diff/1/runtime/lib/bigint.dart File runtime/lib/bigint.dart (right): https://codereview.chromium.org/1205363003/diff/1/runtime/lib/bigint.dart#newcode1565 runtime/lib/bigint.dart:1565: while (x_digits[0].isEven && ...
5 years, 6 months ago (2015-06-25 17:03:13 UTC) #3
Søren Gjesse
lgtm
5 years, 6 months ago (2015-06-26 06:19:45 UTC) #4
Lasse Reichstein Nielsen
https://codereview.chromium.org/1205363003/diff/1/runtime/lib/bigint.dart File runtime/lib/bigint.dart (right): https://codereview.chromium.org/1205363003/diff/1/runtime/lib/bigint.dart#newcode1565 runtime/lib/bigint.dart:1565: while (x_digits[0].isEven && y_digits[0].isEven) { Done. Would it make ...
5 years, 6 months ago (2015-06-26 08:40:40 UTC) #5
Lasse Reichstein Nielsen
Committed patchset #3 (id:40001) manually as 3a0edfba72e27781e98f5debfafc5f01450bd423 (presubmit successful).
5 years, 6 months ago (2015-06-26 09:05:16 UTC) #6
regis
5 years, 6 months ago (2015-06-26 21:49:46 UTC) #7
Message was sent while issue was closed.
https://codereview.chromium.org/1205363003/diff/20001/runtime/lib/bigint.dart
File runtime/lib/bigint.dart (right):

https://codereview.chromium.org/1205363003/diff/20001/runtime/lib/bigint.dart...
runtime/lib/bigint.dart:1754: // }
On 2015/06/26 08:40:40, Lasse Reichstein Nielsen wrote:
> Not sure why this doesn't work - maybe it's because _lsh doesn't clear the low
> bits, and because m_used below is too low (it should also include the bits of
> s).
> For 
>   (693 * pow(2, 99)),gcd(609 * pow(2, 99))
> which should give 21 * pow(2, 99), it gives just 21.
> That would match keeping the low bits at 21 and forgetting the high bits.
> 

That was totally broken. Good that you wrote some gcd tests with even operands.
The problem is that left shift operations need one extra digit (one extra 64-bit
digit on 64-bit platforms), and v_digits does not account for it. Its allocation
length m_len needs adjustment.

Also, the intrinsic _lsh does not clear the low bits, and since we shift in
place, this is not the right one to use.

> I tried changing  _lsh(...)  to  m_used = _dlShiftDigits(...) , but the
v_digits
> array isn't big enough for that (it has an odd length equal to m_used).
> 

That was the right idea, but _dlShiftDigits is the wrong one to use, since it is
a digit shift. We need a bit shift, i.e. _lShiftDigits.

The minimum length calculation in _lShiftDigits and _lShift was too conservative
and can be relaxed.

I'll send a cl to Srdjan (cc'ed) shortly.
 
> So, quick fix that works is to do << after creating a new bigint.

That was the proper workaround. Thanks.

Powered by Google App Engine
This is Rietveld 408576698