widen imprecise fraction cache
This commit is contained in:
parent
5a5288c0a2
commit
b4c07d331d
@ -580,13 +580,13 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
|||||||
@JvmField val DOUBLE_MAX_VALUE = ImpreciseFraction(BI_DOUBLE_MAX)
|
@JvmField val DOUBLE_MAX_VALUE = ImpreciseFraction(BI_DOUBLE_MAX)
|
||||||
@JvmField val DOUBLE_MIN_VALUE = ImpreciseFraction(BI_DOUBLE_MIN)
|
@JvmField val DOUBLE_MIN_VALUE = ImpreciseFraction(BI_DOUBLE_MIN)
|
||||||
|
|
||||||
private val cache = Array(256) { ImpreciseFraction(it - 128) }
|
private val cache = Array(2048) { ImpreciseFraction(it - 1024) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns pooled value if present, otherwise constructs new object
|
* Returns pooled value if present, otherwise constructs new object
|
||||||
*/
|
*/
|
||||||
fun valueOf(value: Int): ImpreciseFraction {
|
fun valueOf(value: Int): ImpreciseFraction {
|
||||||
if (value in -128 .. 127) {
|
if (value in -1024 .. 1024) {
|
||||||
return cache[value + 128]
|
return cache[value + 128]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,7 +597,7 @@ class ImpreciseFraction @JvmOverloads constructor(whole: BigInteger, decimal: Do
|
|||||||
* Returns pooled value if present, otherwise constructs new object
|
* Returns pooled value if present, otherwise constructs new object
|
||||||
*/
|
*/
|
||||||
fun valueOf(value: Long): ImpreciseFraction {
|
fun valueOf(value: Long): ImpreciseFraction {
|
||||||
if (value in -128 .. 127) {
|
if (value in -1024L .. 1024L) {
|
||||||
return cache[value.toInt()]
|
return cache[value.toInt()]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user