diff --git a/CHANGELOG.md b/CHANGELOG.md index 5164567..164385b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## 1.0.26 -- Fix `IterableNumExtension.standardDeviation`. +- Fix: + - `IterableNumExtension.standardDeviation`. + - `IterableDoubleExtension.standardDeviation`. + - `DecimalOnIterableDecimalExtension.standardDeviation`. + - `DynamicIntOnIterableDynamicNumberExtension.standardDeviation`. - sdk: '>=2.14.0 <4.0.0' - intl: ^0.18.1 diff --git a/lib/src/statistics_decimal.dart b/lib/src/statistics_decimal.dart index 02cf7ce..0b0d4df 100644 --- a/lib/src/statistics_decimal.dart +++ b/lib/src/statistics_decimal.dart @@ -1666,7 +1666,7 @@ extension DecimalOnIterableDecimalExtension on Iterable { var average = mean; - var first = itr.current; + var first = itr.current - average; var total = first * first; while (itr.moveNext()) { diff --git a/lib/src/statistics_dynamic_int.dart b/lib/src/statistics_dynamic_int.dart index e0c5b54..876efa6 100644 --- a/lib/src/statistics_dynamic_int.dart +++ b/lib/src/statistics_dynamic_int.dart @@ -1610,7 +1610,7 @@ extension DynamicIntOnIterableDynamicNumberExtension var average = mean; - var first = itr.current; + var first = itr.current - average; var total = first * first; while (itr.moveNext()) { @@ -1690,7 +1690,7 @@ extension DynamicIntOnIterableDynamicIntExtension on Iterable { var average = mean; - var first = itr.current; + var first = itr.current - average; var total = first * first; while (itr.moveNext()) { diff --git a/lib/src/statistics_extension_num.dart b/lib/src/statistics_extension_num.dart index a1d85c1..8817d6a 100644 --- a/lib/src/statistics_extension_num.dart +++ b/lib/src/statistics_extension_num.dart @@ -439,7 +439,7 @@ extension IterableDoubleExtension on Iterable { var average = mean; - var first = itr.current; + var first = itr.current - average; var total = first * first; while (itr.moveNext()) { @@ -731,7 +731,7 @@ extension IterableIntExtension on Iterable { var average = mean; - var first = itr.current; + var first = itr.current - average; var total = (first * first).toDouble(); while (itr.moveNext()) { diff --git a/test/statistics_extension_num_test.dart b/test/statistics_extension_num_test.dart index 5e80d76..f5c03ab 100644 --- a/test/statistics_extension_num_test.dart +++ b/test/statistics_extension_num_test.dart @@ -266,8 +266,8 @@ void main() { test('standardDeviation', () { expect([].standardDeviation, equals(0)); expect([0].standardDeviation, equals(0)); - expect([10].standardDeviation, equals(10)); - expect([10, 20].standardDeviation, equals(7.905694150420948)); + expect([10].standardDeviation, equals(0)); + expect([10, 20].standardDeviation, equals(5)); expect([10, 20, 30].standardDeviation, equals(8.16496580927726)); }); @@ -551,8 +551,8 @@ void main() { test('standardDeviation', () { expect([].standardDeviation, equals(0)); expect([0.0].standardDeviation, equals(0)); - expect([10.0].standardDeviation, equals(10)); - expect([10.0, 20.0].standardDeviation, equals(7.905694150420948)); + expect([10.0].standardDeviation, equals(0)); + expect([10.0, 20.0].standardDeviation, equals(5)); expect([10.0, 20.0, 30.0].standardDeviation, equals(8.16496580927726)); });