bignum

Convert Decimal to Hex when no datatype can hold the full number

This is an almost exact duplicate of my own question a few weeks ago. http://stackoverflow.com/questions/1143302/convert-hex-to-decimal-when-no-datatype-can-hold-the-full-number This time, it is the reverse. I have the number (in a handy null terminated string) and I need the bytes that make this number. However, I am working in a 32 b...

Big Number Subtraction in C

I just finished my exam in an introductory C course about 20 minutes ago. The first question on the exam caught me somewhat off guard, and involved finding the difference two large numbers. The goal was to take two structures (N1 and N2) by value, and store the difference in a structure passed by reference (N3). We were allowed to assum...

bignum in emacs/elisp

Does emacs have support for big numbers that don't fit in integers? If it does, how do I use them? ...

Fastest way to convert binary to decimal?

I've got four unsigned 32-bit integers representing an unsigned 128-bit integer, in little endian order: typedef struct { unsigned int part[4]; } bigint_t; I'd like to convert this number into its decimal string representation and output it to a file. Right now, I'm using a bigint_divmod10 function to divide the number by 10, kee...

Different 32bit-cast into long/__int64, why?

I'm writing my own small multiprecision library, and while writing the method for subtraction, I encountered some weird error. Here is the code block I wrote for for multiprecision subtraction: /* subtraction */ for (; p_aReverseIter != a.m_elements.rend(); ++p_aReverseIter, ++p_bReverseIter) { temp = static_cast<__int64>(static_ca...

Bignum implementation that has efficient addition of small integers

I have been using python's native bignums for an algorithm and decided to try and speed it up by converting it to C++. When I used long longs, the C++ was about 100x faster than the python, but when I used GMP bindings in C++, it was only 10x faster than the python (for the same cases that fit in long longs). Is there a better bignum im...

How to Code a Solution To Deal With Large Numbers?

I'm doing some Project Euler problems and most of the time, the computations involve large numbers beyond int, float, double etc. Firstly, I know that I should be looking for more efficient ways of calculation so as to avoid the large number problem. I've heard of the Bignum libraries. But, for academics interests, I'd like to know how...

Why system can not find the method BigInteger.ToDouble?

I am using F# Interactive, and I have added the reference of FSharp.PowerPack.dll. When I try to convert BigNum to double as the following code, let n = 2N let d = double n error comes out that "System.MissingMethodException: Method not found: 'Double System.Numerics.BigInteger.ToDouble(System.Numerics.BigInteger)'. at Microsoft.F...

Parse bignum into list of 16-bit integers

Hello, I have to implement some bignum arithmetics. The number has to be split into a list of 16 bit integers. That is not the problem. The problem is to parse a string into this notation. If it would be a single integer, i would go through the string backwards, get the number out of the char and would add <number>*10^stringposition. (...

how java.bigInteger valueOf works ?

I'm making a project concerned big numbers without BigInteger, BigDecimal etc. I've managed to do all the basics but now I need to add ability to count factorials. My BigNumber stores data as int[] . Here's a sample solution with BigInteger but I can't use it without having the actual value of my number. BigInteger n = BigInteger.O...

Adding negative and positive numbers in java without BigInt.

Hi, i'm trying to write a small java class. I have an object called BigNumber. I wrote method that add two positive numbers, and other method that subract two also positive numbers. Now i want them to handle negative numbers. So the i wrote couple of 'if' statements eg. if (this.sign == 1 /* means '+' */) { if (sn1.sign == 1) { ...

How can I set the level of precision for Perl's bignum?

I'm trying to use the bignum module in Perl and want to set the precision. I know this can be done via a one liner as detailed on the module's CPAN page: $ perl -Mbignum=p,-50 -le 'print sqrt(20)' ...which will print out the square root of 20 to 50 digits of precision, but what I'm wondering is if there's anyway to set the precision ...

Big float for shader-based mandelbrot explorer

Hi All, I've managed to create a simple mandelbrot explorer using Open Gl, and the CGFX SDK provided by NVidia. It works well, but is currently float based, and therefore doesn't have much "depth" -- As the distance from the lowest complex number to the largest becomes smaller, the precision is lost, and the resultant image is "pixelate...

64 bit negative integers in two's complement form

Hi. I was reading the source of GNU PDF library, particularly their implementation of 64 bit integers. They have defined 64 bit integers as structs of two 32 bit integers - the higher order int is signed and lower order int is unsigned. Here's the relevant code from the header file: /*Definition of internal structure of the pdf_i64_t ...

MPFR rounding issue

I've just started to work with MPFR arbitrary precision library and quite soon encounter very wierd behaviour. The main goal of using it was to improve precision of lagre argument trigs and this works extremly good in MPFR. But then I decided to check out simple math and it was unbeleavable - even in straightforward examples with strict...

How to cut a mpz_t into two parts using GMP lib on C?

Using GMP on c, I have a big integer "mpz_t n" in decimal form, how can I cut it into 2 parts? In fact, these 2 parts should have the same length in binary. For example, maybe I can convert the n to a binary of 112bits, then I want to cut it into 2 56bits parts. Thanks ...

BN_hex2bn magically segfaults in openSSL

Greetings, this is my first post on stackoverflow, and i'm sorry if its a bit long. I'm trying to build a handshake protocol for my own project and am having issues with the server converting the clients RSA's public key to a Bignum. It works in my clent code, but the server segfaults when attempting to convert the hex value of the clie...

What is a convenient base for a bignum library & primality testing algorithm?

Hi, I am to program the Solovay-Strassen primality test presented in the original paper on RSA. Additionally I will need to write a small bignum library, and so when searching for a convenient representation for bignum I came across this specification: struct { int sign; int size; int *tab; } bignum; I will also be writing a m...

Converting arbritrary size strings into arbritrary precision integers (bigints)

Hi, I'm trying to implement the Solovoy-Strassen primality test for arbritrary large integers. I will also be writing a bignum (cannot use 3rd party implementation as this is an academic project). I have decided on the following structure for the bignum: struct { uint64_t *tab; int size; // number of limbs int sign; } I will be...

Multiplication algorithm for abritrary precision (bignum) integers.

Hi, I'm writing a small bignum library for a homework project. I am to implement Karatsuba multiplication, but before that I would like to write a naive multiplication routine. I'm following a guide written by Paul Zimmerman titled "Modern Computer Arithmetic" which is freely available online. On page 4, there is a description of an a...