Coder Social home page Coder Social logo

`gmp_export` equivalent about math HOT 6 CLOSED

brick avatar brick commented on August 22, 2024
`gmp_export` equivalent

from math.

Comments (6)

BenMorel avatar BenMorel commented on August 22, 2024

Hi, the only binary export option available right now is BigInteger::toBytes(), which outputs the number as Big Endian, which may be what you're looking for?

There is currently no support for little endian, and I have no idea what GMP_MSW_FIRST and GMP_LSW_FIRST do. Does that stand for Most/Least Signifiant Word? How many bytes is a word? When is it useful?

from math.

Spomky avatar Spomky commented on August 22, 2024

Hi,

Actually you are right. I just needed to set the second parameter (signed) to false to get it working.

from math.

BenMorel avatar BenMorel commented on August 22, 2024

Glad this is useful to you! Adding an option to control endianness would be nice, though.

from math.

Spomky avatar Spomky commented on August 22, 2024

Yes indeed.
I will propose a PR.

I also tried to find other useful GMP functions such as gmp_setbit or gmp_scan1/gmp_scan0.
I am not sure if such function exist on BCMath side, but it could be nice to add them as wall.

WDYT?

from math.

BenMorel avatar BenMorel commented on August 22, 2024

I'm not against a PR for those, what would you use scan0/scan1 for, though?

from math.

Spomky avatar Spomky commented on August 22, 2024

I needed those method to convert IEEE 754 mantissa/exponent tuples (Spomky-Labs/pki-framework@9d3a37d#diff-1329957db3e8301016690cb1fdcbe53d50611e9cb9ecd5d8c568eb60616c909f).
But the code now looks ugly and non-optimized.
Bit manipulation function would help a lot in this case.
I don't have any other use case in mind, but searching for bits and modify them if something I commonly do when working on crypto libraries (signature, encryption and key conversions).
I will implement the IEEE754 conversion tool here into the CBOR library. At the moment, the library is able to convert the mantissa/exponent into a float/int, but the inversed operation is not yet possible.

from math.

Related Issues (20)

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.