Giter VIP home page Giter VIP logo

kbignum's People

Contributors

soywiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kbignum's Issues

Many questions about BigNum

Hello. First of all, thank you for creating multiplatform libs for Kotlin! I spent hours reading code on Github and documentation. It's useful for entire community.
Let's talk about this library.

  • What version is the latest? With 0.46.0 I'm unable to use the lib because IDEA tells me about pre-release compiler version. With 0.9.0 it works fine.
  • Do you want this lib to be public and used by other people? Because looks like you are not really want to make it as fast as possible.
    A little comparsion between BigDecimal and BigNum shows it:

BigDecimal test 1: ended after 3.947937 ms
BigNum test 1: ended after 61.848497 ms

0.00
0.01
0.02
0.02
0.03
0.03
0.04
0.05
0.05
0.06
BigDecimal test 2: ended after 0.75538 ms

0
0
0
0
0
0
0
0
0
0
BigNum test 2: ended after 2.097193 ms

Code for tests:

val bigDecimals = arrayListOf<BigDecimal>()
    val bigNums = arrayListOf<BigNum>()

    timeCounter(true, "BigDecimal test 1") {
        repeat(10) {
            bigDecimals.add(BigDecimal(it.toString()))
        }
    }

    timeCounter(true, "BigNum test 1") {
        repeat(10) {
            bigNums.add(BigNum(it.toString()))
        }
    }

    val bigDecimal = BigDecimal("173.0")
    val bigNum = BigNum("173.0")

    timeCounter(true, "BigDecimal test 2") {
        repeat(10) {
            println(bigDecimals[it].divide(bigDecimal, 2, RoundingMode.CEILING))
        }
    }

    timeCounter(true, "BigNum test 2") {
        repeat(10) {
            println(bigNums[it].div(bigNum, 2))
        }
    }

So seems like perfomance could be better. Also there is no working divide method and no any RoundingMode option.
Please, tell me you plans for this lib because I really hope to find BigDecimal alternative for multiplatform configuration. I'm not sure that my knowledge in Math can help you...

"-0.0001".bn.toString() Fails: AssertionError: Expected <-0.0001>, actual <0.00-1>.

Hello,

Thanks for all your great work on the Korlibs libraries. Finding a multiplatform arbitrary-precision number library (or even just expect/actualing it on JVM, iOS, and NodeJS) has proved to be a bit of a challenge :).

I have found the following test fails:

assertEquals("-0.0001", "-0.0001".bn.toString())

with

AssertionError: Expected <-0.0001>, actual <0.00-1>.

In the toString() method of BigNum, this line (line 90 in my copy of the source, v1.10.1):

"0." + "0".repeat(-pos) + out

is not taking negativity of the number into consideration, so the "-" is going with "out" instead of being prefixed to the entire number.

As a workaround in my local I have added this extension method:

fun BigNum.toStringCorrected(): String {
//return "BigNum($int, $scale)"
val isNegative = int < BigInt.ZERO
val out = "${int.abs()}"
val pos = out.length - scale
return (if (isNegative) "-" else "") + if (pos <= 0) {
"0." + "0".repeat(-pos) + out
} else {
(out.substring(0, pos) + "." + out.substring(pos)).trimEnd('.')
}
}

I haven't extensively tested it yet, but this could be a possible solution.

Thanks for your efforts!

Richard

BigInt from hex string incorrect on iOS

v2.4.12

println(BigInt("616e794474736574", 16).toString())

Outputs

jvm (correct):

7020682204035638644

ios (incorrect):

1953719668

v2.4.1.1 has the correct output for both

BigNum.div with precision is broken

fun div(other: BigNum, precision: Int): BigNum

is broken, it does not take into account precision parameter at all.

The implementation should be something like:

operator fun div(other: BigNum, precision: Int = other.int.significantBits / 2): BigNum {
return BigNum(int * (10.bi pow (other.scale + precision)) / other.int, scale) * BigNum(1.bi, precision)
}

[Feature request] Support ranges

Hello! This improvement should help to integrate kbignum with Kotlin.
When I have such a simple case to iterate from one bignum to another one, I should write such a function right now:
Снимок экрана 2021-11-11 в 12 59 10

Dead link

In README.md we find
Maven Version
with a link that is a search which only finds a ScalaJS Library? Will you publish the library on a repository as a pom any time soon?

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.