diff --git a/CHANGELOG.md b/CHANGELOG.md index 95fc2a2..27b9788 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.3 + +- `Decimal`: + - `_divideOperationByDynamicIntImpl2`: fix operation with therms of different signals (`-/+` or `+/-`). + ## 1.1.2 - sdk: '>=3.4.0 <4.0.0' diff --git a/lib/src/statistics_decimal.dart b/lib/src/statistics_decimal.dart index 8e3adef..bcc598a 100644 --- a/lib/src/statistics_decimal.dart +++ b/lib/src/statistics_decimal.dart @@ -1183,11 +1183,20 @@ class Decimal implements DynamicNumber { var r2 = r.multiplyDynamicInt(r2Scale); var r2Div = r2 ~/ n; - while (r2Precision < 15 && (r2Div.multiplyDynamicInt(n)) < r2) { - r2 = r2.multiplyDynamicInt(r2Scale); - r2Div = r2 ~/ n; - r2Precision *= 2; - r2Scale = r2Scale.multiplyDynamicInt(r2Scale); + if (r2.isNegative) { + while (r2Precision < 15 && r2Div.multiplyDynamicInt(n) > r2) { + r2 = r2.multiplyDynamicInt(r2Scale); + r2Div = r2 ~/ n; + r2Precision *= 2; + r2Scale = r2Scale.multiplyDynamicInt(r2Scale); + } + } else { + while (r2Precision < 15 && r2Div.multiplyDynamicInt(n) < r2) { + r2 = r2.multiplyDynamicInt(r2Scale); + r2Div = r2 ~/ n; + r2Precision *= 2; + r2Scale = r2Scale.multiplyDynamicInt(r2Scale); + } } d = d.multiplyDynamicInt(r2Scale).sumDynamicInt(r2Div); diff --git a/lib/src/statistics_extension.dart b/lib/src/statistics_extension.dart index 2308845..c18d282 100644 --- a/lib/src/statistics_extension.dart +++ b/lib/src/statistics_extension.dart @@ -326,8 +326,9 @@ extension ListExtension on List { return [a, b, c]; } } else if (c == d) { + assert(a != c); if (a == b) { - return a == c ? [a] : [a, c]; + return [a, c]; } else { return [a, b, c]; } diff --git a/pubspec.yaml b/pubspec.yaml index 6f7c86b..09658b7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: statistics description: Statistics package for easy and efficient data manipulation with built-in Bayesian Network (Bayes Net), many mathematical functions and tools. -version: 1.1.2 +version: 1.1.3 homepage: https://github.com/gmpassos/statistics environment: diff --git a/test/statistics_decimal_test.dart b/test/statistics_decimal_test.dart index 5d5bcb7..6fac5fe 100644 --- a/test/statistics_decimal_test.dart +++ b/test/statistics_decimal_test.dart @@ -1163,6 +1163,18 @@ void main() { (1000000.toDecimal().divideBigIntAsDecimal(2.toBigInt())) .toStringStandard(), equals('500000.0')); + + expect(Decimal.parse('500.0') / Decimal.parse('55597.463309718'), + equals(Decimal.parse('0.008993216061219'))); + + expect(Decimal.parse('-500.0') / Decimal.parse('-55597.463309718'), + equals(Decimal.parse('0.008993216061219'))); + + expect(Decimal.parse('-500.0') / Decimal.parse('55597.463309718'), + equals(Decimal.parse('-0.008993216061219'))); + + expect(Decimal.parse('500.0') / Decimal.parse('-55597.463309718'), + equals(Decimal.parse('-0.008993216061219'))); }); test('operation %', () { diff --git a/test/statistics_extension_test.dart b/test/statistics_extension_test.dart index f46803a..da712b9 100644 --- a/test/statistics_extension_test.dart +++ b/test/statistics_extension_test.dart @@ -170,6 +170,9 @@ void main() { expect(['10', '30', '30', '30'].toDistinctList(), allOf(isA>(), equals(['10', '30']))); + expect(['30', '20', '30', '30'].toDistinctList(), + allOf(isA>(), equals(['30', '20']))); + expect(['10', '10', '20', '30', '40', '50'].toDistinctList(), allOf(isA>(), equals(['10', '20', '30', '40', '50'])));