blob: 16fbb1736121e46ab46181c99661ea4ef1aa6c93 [file] [log] [blame]
// Copyright (c) 2011, 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.
/// @assertion num remainder(num other)
/// Returns the remainder of the truncating division of this by other.
///
/// The result r of this operation satisfies: this == (this ~/ other) * other + r.
/// As a consequence the remainder r has the same sign as the divider this.
/// @author vasya
import "../../../Utils/expect.dart";
import "dart:math" as Math;
main() {
check(0.0, 1, 0.5);
check(0.0, 1, -0.5);
check(0.25, 1, 0.375);
check(0.25, 1, -0.375);
check(-0.25, -1, 0.375);
check(-0.25, -1, -0.375);
final double MIN_DOUBLE = Math.pow(2.0, -1074) as double;
final double NEG_MIN_DOUBLE = -1 * MIN_DOUBLE;
final double MAX_DOUBLE =
(2 - Math.pow(2.0, -52)) * Math.pow(2.0, 1023) as double;
final double NEG_MAX_DOUBLE = -1 * MAX_DOUBLE;
check(0, 0, MIN_DOUBLE);
check(0, 0, NEG_MIN_DOUBLE);
check(0, 0, MAX_DOUBLE);
check(0, 0, NEG_MAX_DOUBLE);
check(1, 1, MAX_DOUBLE);
check(1, 1, NEG_MAX_DOUBLE);
check(1, 1, double.infinity);
check(-1, -1, double.infinity);
check(1, 1, double.negativeInfinity);
check(-1, -1, double.negativeInfinity);
check(0x1000000000000000, 0x1000000000000000, double.infinity);
check(-0x1000000000000000, -0x1000000000000000, double.infinity);
check(0x1000000000000000, 0x1000000000000000, double.negativeInfinity);
check(-0x1000000000000000, -0x1000000000000000, double.negativeInfinity);
Expect.isTrue((1.remainder(0.0)).isNaN);
Expect.isTrue((1.remainder(-0.0)).isNaN);
Expect.isTrue((-1.remainder(0.0)).isNaN);
Expect.isTrue((-1.remainder(-0.0)).isNaN);
Expect.isTrue((0.remainder(0.0)).isNaN);
Expect.isTrue((0.remainder(-0.0)).isNaN);
Expect.isTrue((0x1000000000000000.remainder(0.0)).isNaN);
Expect.isTrue(((-0x1000000000000000).remainder(0.0)).isNaN);
Expect.isTrue((1.remainder(double.nan)).isNaN);
Expect.isTrue((0x1000000000000000.remainder(double.nan)).isNaN);
Expect.isTrue(((-0x1000000000000000).remainder(double.nan)).isNaN);
}
void check(num ex, int a, double b) {
Expect.equals(ex, a.remainder(b));
Expect.isTrue(a.remainder(b) is double);
Expect.runtimeIsType<double>(a.remainder(b));
}