diff --git a/lib/utils/bytes.dart b/lib/utils/bytes.dart index f1cf4e3..9c2f3c1 100644 --- a/lib/utils/bytes.dart +++ b/lib/utils/bytes.dart @@ -43,7 +43,7 @@ class Bytes { return n / pow(dimension.value, index); } - int get unitIndex => min(index, type.units.length); + int get unitIndex => index.clamp(0, type.units.length); bool get _isInvalid => n.isNaN || n.isInfinite || n.isZero || n.isNegative; @@ -165,7 +165,7 @@ class _Bits extends Bytes { UnitType get type => .bit; @override - int get unitIndex => min(index, type.units.length); + int get unitIndex => index.clamp(0, type.units.length); @override String toString([String separator = ""]) { diff --git a/lib/utils/speed_monitor.dart b/lib/utils/speed_monitor.dart index be57e49..0c32f2d 100644 --- a/lib/utils/speed_monitor.dart +++ b/lib/utils/speed_monitor.dart @@ -43,8 +43,7 @@ class SpeedMonitor implements Disposable { if (first == last) return _zero; - return last.units - - first.units / last.time - - first.time / _windowDuration.inMicroseconds; + return (last.units - first.units) / + ((last.time - first.time) / _windowDuration.inMicroseconds); } } diff --git a/test/utils/bytes_test.dart b/test/utils/bytes_test.dart index 49a1bff..2365bd5 100644 --- a/test/utils/bytes_test.dart +++ b/test/utils/bytes_test.dart @@ -34,5 +34,10 @@ void main() { const Bytes bytes = .bits(1024 * 1024 * 10 * 8); expect(bytes.toString(), "80.0Mb"); }); + + test("${4.996949731576378e-7 * 8}", () { + const Bytes bytes = .bits(4.996949731576378e-7 * 8); + expect(bytes.toString(), "0.0b"); + }); }); }