@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.math
3
3
import org.jetbrains.kotlinx.dataframe.api.skipNA_default
4
4
import org.jetbrains.kotlinx.dataframe.impl.renderType
5
5
import java.math.BigDecimal
6
+ import java.math.BigInteger
6
7
import kotlin.reflect.KType
7
8
import kotlin.reflect.full.withNullability
8
9
@@ -28,6 +29,8 @@ internal fun <T : Number> Sequence<T>.mean(type: KType, skipNA: Boolean = skipNA
28
29
29
30
Long ::class -> (this as Sequence <Long >).map { it.toDouble() }.mean(false )
30
31
32
+ BigInteger ::class -> (this as Sequence <BigInteger >).map { it.toDouble() }.mean(false )
33
+
31
34
BigDecimal ::class -> (this as Sequence <BigDecimal >).map { it.toDouble() }.mean(skipNA)
32
35
33
36
Number ::class -> (this as Sequence <Number >).map { it.toDouble() }.mean(skipNA)
@@ -132,6 +135,19 @@ public fun Iterable<Long>.mean(): Double =
132
135
if (count > 0 ) sum / count else Double .NaN
133
136
}
134
137
138
+ @JvmName(" bigIntegerMean" )
139
+ public fun Iterable<BigInteger>.mean (): Double =
140
+ if (this is Collection ) {
141
+ if (size > 0 ) sumOf { it.toDouble() } / size else Double .NaN
142
+ } else {
143
+ var count = 0
144
+ val sum = sumOf {
145
+ count++
146
+ it.toDouble()
147
+ }
148
+ if (count > 0 ) sum / count else Double .NaN
149
+ }
150
+
135
151
@JvmName(" bigDecimalMean" )
136
152
public fun Iterable<BigDecimal>.mean (): Double =
137
153
if (this is Collection ) {
0 commit comments