🚀 What's new in Kotools Types 5.2.0 #1049
LVMVRQUXL
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Kotools Types 5.2.0 is out, and it's the biggest release yet for
org.kotools.types.number. Four changes stand out. Each gets its own dedicated, deep-dive article — this post is the short tour.🧮
Integergot a faster internal representationBefore 5.2.0,
Integerstored its value as aStringand reparsed it on every arithmetic operation. That representation is gone:Integernow delegates tojava.lang.BigIntegeron Kotlin/JVM,BigInton Kotlin/JS, and a custom arbitrary-precision implementation on Kotlin/Native — with no parsing involved in+,-,*,div, orrem. This was one of the most frequently requested changes from the community.🎯
Decimalarrives: exact arithmetic without floating-point0.1 + 0.2 != 0.3is a classic trap withDouble/Float, because binary floating-point can't exactly represent most base-10 decimals.Decimal, a brand-new type inorg.kotools.types.number, sidesteps the problem entirely by never using floating-point in the first place — addition, subtraction, and multiplication are always exact.➗
Integerdivision is now Euclidean, and totalInteger.divandInteger.remnow always satisfy0 <= remainder < |divisor|— no more negative remainders depending on the sign of the operands. The divisor is also now aNonZeroInteger, a type that rules out division by zero at compile time, so these operations can no longer throw or returnnullbecause of a zero divisor.🔒 Sign as a type:
NonZeroInteger,NonNegativeInteger,NonPositiveIntegerThree new types turn "this integer can never be negative" (or positive, or zero) from a runtime check into a compile-time guarantee, with arithmetic operators that preserve those guarantees across additions and multiplications.
🛠️ Adding Kotools Types to your project
See the Installation section of the project's README for Gradle/Maven setup — this article was written against version
5.2.0.This API is
@ExperimentalKotoolsTypesApi, so opt in either per call-site with@OptIn(ExperimentalKotoolsTypesApi::class)or project-wide via the compiler argument:See also: GitHub, API reference
💬 Discussion
Which of these four changes affects your code the most?
Beta Was this translation helpful? Give feedback.
All reactions