Skip to content

Commit

Permalink
Merge v1.1.3
Browse files Browse the repository at this point in the history
 - `Decimal`:
   - `_divideOperationByDynamicIntImpl2`: fix operation with therms of different signals (`-/+` or `+/-`).
  • Loading branch information
gmpassos authored Sep 11, 2024
2 parents 4e3d552 + 7a28572 commit dbbf930
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 14 additions & 5 deletions lib/src/statistics_decimal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1183,11 +1183,20 @@ class Decimal implements DynamicNumber<Decimal> {
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);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/statistics_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ extension ListExtension<T> on List<T> {
return <T>[a, b, c];
}
} else if (c == d) {
assert(a != c);
if (a == b) {
return a == c ? <T>[a] : <T>[a, c];
return <T>[a, c];
} else {
return <T>[a, b, c];
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
12 changes: 12 additions & 0 deletions test/statistics_decimal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 %', () {
Expand Down
3 changes: 3 additions & 0 deletions test/statistics_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ void main() {
expect(['10', '30', '30', '30'].toDistinctList(),
allOf(isA<List<String>>(), equals(['10', '30'])));

expect(['30', '20', '30', '30'].toDistinctList(),
allOf(isA<List<String>>(), equals(['30', '20'])));

expect(['10', '10', '20', '30', '40', '50'].toDistinctList(),
allOf(isA<List<String>>(), equals(['10', '20', '30', '40', '50'])));

Expand Down

0 comments on commit dbbf930

Please sign in to comment.