Concept of infinity, for Decimals

This commit is contained in:
DBotThePony 2023-12-28 20:13:03 +07:00
parent 6784271ac7
commit f13c725298
Signed by: DBot
GPG Key ID: DCC23B5715498507
3 changed files with 1326 additions and 470 deletions

File diff suppressed because it is too large Load Diff

View File

@ -167,6 +167,8 @@ fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsR
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 3, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
if (this == Decimal.POSITIVE_INFINITY) return concat("", suffix)
if (this == Decimal.NEGATIVE_INFINITY) return concat("-∞", suffix)
if (formatAsReadable.asBoolean && this.absoluteValue >= Decimal.ONE) return concat(reformat(toString(decimalPlaces)), suffix)
val prefix = SiPrefix.determine(this)
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, (this / prefix.decimal).toString(decimalPlaces), suffix)

View File

@ -121,7 +121,7 @@ enum class SiPrefix(val power: Int, val symbol: String) {
}
fun determine(value: Decimal, bias: Int = 0): SiPrefix {
if (value.isZero) {
if (value.isZero || value.isInfinite) {
return NONE
}