largenumber

Inputting large numbers in c++?

What's the best way to handle large numeric inputs in c++ (eg 10^100)? For algorithms I usually switch over to ruby and I sometimes use strings. Any other good methods? ...

Big integers in C#

Currently I am borrowing java.math.BigInteger from the J# libraries as described here. Having never used a library for working with large integers before, this seems slow, on the order of 10 times slower, even for ulong length numbers. Does anyone have any better (preferably free) libraries, or is this level of performance normal? ...

How to round/ceil/floor a bcmath number in PHP?

Is there any library function for this purpose, so I don't do it by hand and risk ending in TDWTF? echo ceil(31497230840470473074370324734723042.6); // Expected result 31497230840470473074370324734723043 // Prints <garbage> ...

How do you do maths (or math) with numbers bigger than MaxValue in C#?

I want to be able to process arbitrarily large numbers in C#. I can live with just integers. Are there established algorithms for this kind of thing? Or is there a good 3rd-party library? I might consider changing language if there really is no good way to do it in C#. Thanks for any help / suggestions. ...

How to implement big int in C++

Hi, I'd like to implement a big int class in C++ as a programming exercise. A class that can handle numbers bigger then a long int. I know that there are several open source implementations out there already, but I'd like to write my own. I trying to get a feel for what the right approach is. I understand that the general strategy i...

working with incredibly large numbers in .NET

I'm trying to work through the problems on projecteuler.net but I keep running into a couple of problems. The first is a question of storing large quanities of elements in a List<t>. I keep getting OutOfMemoryException's when storing large quantities in the list. Now I admit I might not be doing these things in the best way but, is the...

How can I add very large numbers in C++?

How can I add very large numbers in C++? ...

Which libraries for handling very large integers in languages without native support?

Various questions (like this, and this) ask about how to handle integer values exceeding the native types of a particular language. Please reply here, with one response per language, recommendations for libraries designed for handling very large numbers in various languages. Where languages have built-in support for large numbers that'...

How do I multiply (and divide) BCD numbers by 10^x

I have a large (12 digit) BCD number, encoded in an array of 6 bytes - each nibble is one BCD digit. I need to multiply it by 10^x, where x can be positive or negative. I know it can be done by shifting left or right by nibble instead of bit, but it's a horrible implementation - especially in Javacard, which is what I'm using. Is there...

Types for large numbers

I am working on an app that will need to handle very large numbers. I checked out a few available LargeNumber classes and have found a few that I am happy with. I have a class for large integers and for large floating point numbers. Since some of the numbers will be small and some large the question is whether it is worth checking the ...

How to divide big numbers?

I have a big number (integer, unsigned) stored in 2 variables (as you can see, the high and low part of number): unsigned long long int high; unsigned long long int low; I know how to add or subtract some other that-kind of variable. But I need to divide that-kind of numbers. How to do it? I know, I can subtract N times, but, maybe, ...

a more simple big adder in c#?

Hi, I just had the task in school to write a big adder. Meaning a method that can put very large numbers together. We had 10 minutes and I did complete it on time. The teacher approved it. I am not too satisfied with the result though, and I thought I perhaps were taking the wrong approach. Here is my version: using System; using Sys...

What is the logic behind Fourier division algorithm?

from Wikipedia: fourier division. Here is a screenshot of the same: (view in full-resolution) What is the logic behind this algorithm? I know it can be used to divide very large numbers, but how exactly does it work? ...

convert astronomically large numbers into human readable form in C/C++

My program prints out HUGE numbers - like 100363443, up to a trillion -- and it sort of hard to read them, so I would like to print any number in easy to read form. right now I use printf ("%10ld", number); format I would appreciate a resulting number using printf. Most of my code is c++ yet I don't want to introduce std::cout, as...

How to calculate "modular multiplicative inverse" when the denominator is not co-prime with m?

I need to calculate (a/b) mod m where a and b are very large numbers. What I am trying to do is to calculate (a mod m) * (x mod m), where x is the modular inverse of b. I tried using Extended Euclidean algorithm, but what to do when b and m are not co-prime? It is specifically mentioned that b and m need to be co-prime. I tried using ...

PHP integer exponentiation (super large numbers)

Using PHP I want to do millions of 2^n exponentiation but so far I only got up to n^1023 before PHP printed INF. Any ideas? ...

Calculating variance with large numbers

I haven't really used variance calculation that much, and I don't know quite what to expect. Actually I'm not too good with math at all. I have a an array of 1000000 random numeric values in the range 0-10000. The array could grow even larger, so I use 64 bit int for sum. I have tried to find code on how to calc variance, but I don't ...

More efficient method for this calculation?

a = 218500000000 s = 6 f = 2 k = 49 d = k + f + s r = a i = 0 while (r >= d): r = r - d #print ('r = ',r) i = i+1 #print ('i = ',i) print (i) I think it does what I expect it to, but its way too slow to calculate such a large number, I waited 5 mins for i to print (while python used 100% cpu to calculate..), but it didn't. ...

Handling numbers larger than Long in VBA

I am Currently trying to write some code in VBA to solve a problem from Project Euler. I have been trying to answer a question that requires you to find primes that can be divided into a number that will not fit in a long. Any suggestions as how to handle this problem? I know I can split the number between two variables and I have ...

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...