@@ -936,11 +936,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
936
936
937
937
/** Sums the elements of this collection.
938
938
*
939
- * The default implementation uses `reduce` for a known non-empty collection,
940
- * `foldLeft` otherwise.
941
- *
942
- * If `foldLeft` is used, this implementation works around pollution of the math context
943
- * by ignoring the identity element.
939
+ * The default implementation uses `reduce` for a known non-empty collection, `foldLeft` otherwise.
944
940
*
945
941
* $willNotTerminateInf
946
942
*
@@ -951,24 +947,14 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
951
947
*/
952
948
def sum [B >: A ](implicit num : Numeric [B ]): B =
953
949
knownSize match {
954
- case - 1 =>
955
- val z = num.zero
956
- if ((num eq Numeric .BigDecimalIsFractional ) || (num eq Numeric .BigDecimalAsIfIntegral )) {
957
- def nonPollutingPlus (x : B , y : B ): B = if (x.asInstanceOf [AnyRef ] eq z.asInstanceOf [AnyRef ]) y else num.plus(x, y)
958
- foldLeft(z)(nonPollutingPlus)
959
- }
960
- else foldLeft(z)(num.plus)
950
+ case - 1 => foldLeft(num.zero)(num.plus)
961
951
case 0 => num.zero
962
952
case _ => reduce(num.plus)
963
953
}
964
954
965
955
/** Multiplies together the elements of this collection.
966
956
*
967
- * The default implementation uses `reduce` for a known non-empty collection,
968
- * `foldLeft` otherwise.
969
- *
970
- * If `foldLeft` is used, this implementation works around pollution of the math context
971
- * by ignoring the identity element.
957
+ * The default implementation uses `reduce` for a known non-empty collection, `foldLeft` otherwise.
972
958
*
973
959
* $willNotTerminateInf
974
960
*
@@ -979,13 +965,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] =>
979
965
*/
980
966
def product [B >: A ](implicit num : Numeric [B ]): B =
981
967
knownSize match {
982
- case - 1 =>
983
- val u = num.one
984
- if ((num eq Numeric .BigDecimalIsFractional ) || (num eq Numeric .BigDecimalAsIfIntegral )) {
985
- def nonPollutingProd (x : B , y : B ): B = if (x.asInstanceOf [AnyRef ] eq u.asInstanceOf [AnyRef ]) y else num.times(x, y)
986
- foldLeft(u)(nonPollutingProd)
987
- }
988
- else foldLeft(u)(num.times)
968
+ case - 1 => foldLeft(num.one)(num.times)
989
969
case 0 => num.one
990
970
case _ => reduce(num.times)
991
971
}
0 commit comments