mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
ef42a0b110
Closes https://github.com/dart-lang/sdk/pull/50860 GitOrigin-RevId: b27066c37f93c8c6d1123d6ebd6a4c0afcf59844 Change-Id: I15fa4aea1dad45daf168e34d1c4450320ec9b40a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277742 Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Extreme values from int_modulo_arith_test. Test cases that have
|
|
// intermediate values that overflow the precision of 'int'.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
import "dart:math" show pow;
|
|
|
|
main() {
|
|
test(x, e, m, expectedResult) {
|
|
var result = x.modPow(e, m);
|
|
Expect.equals(expectedResult, result, "$x.modPow($e, $m)");
|
|
}
|
|
|
|
for (int mBase in [
|
|
50000000,
|
|
94906266, // Smallest integer with square over 2^53.
|
|
100000000,
|
|
1000000000,
|
|
3037000500, // Smallest integer with square over 2^63.
|
|
4000000000,
|
|
0x7FFFFFFFFFFFF000 + 0xFFC
|
|
]) {
|
|
// On 'web' platforms skip values outside web number safe range.
|
|
if (mBase == mBase + 1) continue;
|
|
|
|
for (int mAdjustment in [0, 1, 2, 3, -1]) {
|
|
int m = mBase + mAdjustment;
|
|
for (int e = 1; e < 100; e++) {
|
|
// Test "M-k ^ N mod M == (-k) ^ N mod M" for some small values of k.
|
|
test(m - 1, e, m, pow(-1, e) % m);
|
|
if (e < 53) {
|
|
test(m - 2, e, m, pow(-2, e) % m);
|
|
}
|
|
if (e < 33) {
|
|
test(m - 3, e, m, pow(-3, e) % m);
|
|
}
|
|
if (e < 26) {
|
|
test(m - 4, e, m, pow(-4, e) % m);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|