Open ikasiuk opened 12 years ago
Yeah, well this is probably pretty painful, unless we can find something already existing in open source. Which is one reason I had for deciding to move them out of ceylon.language
and into a new module ceylon.math
which we won't immediately need a js implementation of.
Moving to 1.0
A Google search for "javascript biginteger" indicates there's a number of existing implementations of BigInteger, with a performance comparison post. There's also an implementation of the Scheme number tower.
I'm not familiar with the SDK code so I can't say how difficult integrating existing solutions would be. However, a lack of Decimal/Whole also blocks implementing the ceylon.math
module in JS and exposing some basic math functions, unless that module is split again as suggested in this issue: ceylon/ceylon-sdk#103.
@rimmington thanks for those links. BigInteger
probably isn't all that difficult to implement or reuse. I think BigDecimal
is would be more challenging. From the pages you linked to I found https://github.com/iriscouch/bigdecimal.js (ASL 2 licensed) , which is basically what GWT is supposed to use. https://github.com/MikeMcl/bignumber.js (MIT license) reckons there are some serious bugs in that, but also links to https://github.com/dtrebbien/BigDecimal.js (exact license unclear but libre and gratis)
So it seems like there might be three things we could base a JS implementation of Decimal
on.
But there are also some other issues like ceylon/ceylon-spec#499 which might need to be overcome in doing this.
FTR, the license for https://github.com/dtrebbien/BigDecimal.js is here: http://source.icu-project.org/repos/icu/icu4j/tags/release-2-4/license.html
Moved to 1.1
I am working on a JavaScript big decimal implementation, and this one is released to the public domain.
Are you interested?
Sure! Where can I see it?
It's in my Git repository CBOR:
https://github.com/peteroupc/CBOR/tree/master/js
I've just updated it now.
There are two versions: BigNumber.js and the minified BigNumberMin.js. They are translations of the BigInteger, DecimalFraction, and BigFloat classes from the Java and C# versions. Documentation is included in the wiki. Even though it describes the Java version, the JavaScript version is largely the same.
One thing, though, it that it has limited support for converting objects, other than strings, to and from big numbers. Only string conversion works well. However, I will expand and adapt it to fit your needs.
Thank you very much for this. We will probably need to modify it (slightly, I hope) and use it internally, instead of turning it directly into a Ceylon type.
Has someone started to use or adapt my JavaScript implementation yet?
no not yet, sorry. I hope it's not that complicated, but we need to "ceylonify" this, maybe modify the code or have a wrapper around the native js code, so that we have the same types working in both backends (each with their native impl).
We don't have BigDecimal and BigInteger as in Java. So we need a JS implementation if we want to support these types.