Git Product home page Git Product logo

Comments (3)

Daninet avatar Daninet commented on June 21, 2024

Thank you for sharing your ideas!

I started with a mutable wrapper, but I dropped it. It turned out that immutable wrappers have comparable performance, while providing a more JavaScript-friendly API. All of the low-level GMP / MPFR functions are also exposed so those can be used when somebody wants to do advanced optimizations. https://github.com/Daninet/gmp-wasm#advanced-usage. You can even mix the high level wrapper with low level code, by accessing the mpz_t pointer from the wrapper.

"Bit slice" read feature wouldn't be a same as doing a shiftRight() + bitwise and() with a bitmask? I see that GMP has functions for manipulating individual bits, maybe those could be exposed in the wrapper.

I like the idea of byte array I/O. I will try to add it to the next version.

from gmp-wasm.

danwallach avatar danwallach commented on June 21, 2024

You could definitely implement bit slicing with shifting and masking. I suppose it might be faster to do all that on the inside and just let me ask for a specific range of bits.

For byte arrays, gmpy gives you a "portable" output with a two byte header. You probably want to be interoperable with that as well as the Java version (no header).

from gmp-wasm.

Daninet avatar Daninet commented on June 21, 2024

I added some new Integer functions to version 0.8.2:

setBit(index)
setBits(indices)
clearBit(index)
clearBits(indices)
flipBit(index)
flipBits(indices)
getBit(index)
msbPosition()
sliceBits(start, end) => Works similarly to JS Array.slice(), but on bits. It supports negative offsets.
writeTo(num, offset, bitCount) => Can be used to put an another integer somewhere in the middle of the binary representation
toBuffer(littleEndian = false) => Exports Uint8Array without any extra headers. Sign is not included
toString(radix = 10) has now an optional radix parameter

Uint8Array buffers are also supported by the constructor:
ctx.Integer(ctx.Integer('1234567').toBuffer())

Now it also possible to use create and read strings in arbitrary bases:
ctx.Integer(6).toString(7)
ctx.Integer('110', 2)

from gmp-wasm.

Related Issues (5)

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.