Files
sdk/tests/language/operator/truncdiv_test.dart
T
Lasse R.H. Nielsen 2c36db9b0a Deprecate IntegerDivisionByZeroException.
Deprecates the class and makes it implement `Error` (more specifically
`UnsupportedError`).
Code throwing `IntegerDivisionByZeroException` should be migrated to
throwing `unsupportedError` directly, code catching the exception class
should start catching `UnsupportedError` immediately (or reconsider why
they are catching at all).

Integer division by zero also covers other ways that a double division
can give a non-number result (any infinity or NaN result of the division prior to calling `truncate()` on the result, will cause `~/` to throw).

Fixes #46776

Bug: https://github.com/dart-lang/sdk/issues/46776
Change-Id: Idf2657153dd16542e72c6ba921f587dd9fc9032a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208643
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2021-10-19 16:07:52 +00:00

36 lines
927 B
Dart

// Copyright (c) 2013, 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.
// Dart test optimization of modulo operator on Smi.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
import "package:expect/expect.dart";
main() {
for (int i = -30; i < 30; i++) {
Expect.equals(i % 9, foo(i, 9));
// Zero test is done outside the loop.
if (i < 0) {
Expect.equals(i ~/ -i, foo2(i));
} else if (i > 0) {
Expect.equals(i ~/ i, foo2(i));
}
}
// We don't specify the exact exception type here, that is covered in
// truncdiv_zero_test.
Expect.throws<UnsupportedError>(() => foo2(0));
}
foo(i, x) => i % x;
foo2(i) {
// Make sure x has a range computed.
var x = 0;
if (i < 0) {
x = -i;
} else {
x = i;
}
return i ~/ x;
}