Code Monkey home page Code Monkey logo

bigint's Introduction

BigInt

Kotlin Multiplatform implementation of arbitrary-precision integers. For use in cross-platform applications without the need of expect/actual declarations.

Maven Dependency

Coming Soon

Usage

Extension functions are provided for easy conversion.

// From Int
1234567.toBigInteger()
// From Long
123456789012345678L.toBigInteger()
// From String
"123456789012345678901234567890".toBigInteger()

TODOs

  • Improve performance, especially of String.toBigInteger()
  • Support pow, exp, log, and other operations

bigint's People

Contributors

juggernaut0 avatar

Watchers

 avatar

bigint's Issues

Status of the project

Hello, @juggernaut0. Thank you for your work! Do you plan to make this library usable for everyone? Or it's just your personal solution?

I'm trying to find a cross-platform alternative to BigDecimal (which is obviously should be based on BigInteger) so your project looks promising. For now it's pretty buggy but bugs are not the only problem. Performance could be better.
I created my BigInteger and BigDecimal implementations but they have worse performance than your BigInteger :)

Some of the bugs I found while testing:
Wrong sum in some corner cases:

After this line:
https://github.com/juggernaut0/bigint/blob/master/src/commonMain/kotlin/com/github/juggernaut0/bigint/BigInteger.kt#L91

add:
if (carry > 0u) result[len] = carry.toUByte()

Wrong comparsion with negative values:

After this line:
https://github.com/juggernaut0/bigint/blob/master/src/commonMain/kotlin/com/github/juggernaut0/bigint/BigInteger.kt#L191

add:
val higher = if (neg) -1 else 1
val lower = if (neg) 1 else -1

change:
https://github.com/juggernaut0/bigint/blob/master/src/commonMain/kotlin/com/github/juggernaut0/bigint/BigInteger.kt#L197
https://github.com/juggernaut0/bigint/blob/master/src/commonMain/kotlin/com/github/juggernaut0/bigint/BigInteger.kt#L198

with:
if (a > b) return higher
if (a < b) return lower

Also divmod() method doesn't work in some situations. Can't show to you the correct code because I made another method for myself which do the same with different code. But to find an issues try to divide numbers like:
-something / something
something / -something
-something / - something

and you'll find wrong results. I just used BigInteger from Jvm for comparsion.

I searched some days ago over the github and in other popular sources for BigDecimal/BigInteger projects based on Kotlin-only and found a few but its can not be used in production. I really hope that you'll continue to work on this library and we will promote you somehow. I'm not alone who trying to find working multiplatform code for big numbers.
So, what's you plans?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.