bignum

Can long integer routines benefit from SSE?

☆樱花仙子☆ 提交于 2019-11-26 16:41:48
问题 I'm still working on routines for arbitrary long integers in C++. So far, I have implemented addition/subtraction and multiplication for 64-bit Intel CPUs. Everything works fine, but I wondered if I can speed it a bit by using SSE. I browsed through the SSE docs and processor instruction lists, but I could not find anything I think I can use and here is why: SSE has some integer instructions, but most instructions handle floating point. It doesn't look like it was designed for use with

Most efficient implementation of a large number class

孤街醉人 提交于 2019-11-26 14:44:22
问题 When doing calculations on very large numbers where integral data types such as double or int64 falls short, a separate class to handle such large numbers may be needed. Does anyone care to offer an efficient algorithm on how best to do this? 回答1: There are 2 solutions to your problem: Easy way: Use an external library such as 'The GNU MP Bignum Library and forget about implementation details. Hard way: Design your own class/structure containing multiple higher order datatypes like double or

Efficient Multiply/Divide of two 128-bit Integers on x86 (no 64-bit)

大兔子大兔子 提交于 2019-11-26 14:30:31
问题 Compiler: MinGW/GCC Issues: No GPL/LGPL code allowed (GMP or any bignum library for that matter, is overkill for this problem, as I already have the class implemented). I have constructed my own 128-bit fixed-size big integer class (intended for use in a game engine but may be generalized to any usage case) and I find the performance of the current multiply and divide operations to be quite abysmal (yes, I have timed them, see below), and I'd like to improve on (or change) the algorithms that

Best bignum library to solve Project Euler problems in C++? [closed]

十年热恋 提交于 2019-11-26 14:14:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am still a student, and I find project Euler very fun. sometimes the question requires calculations that are bigger than primitive types. I know you can implement it but I am too lazy to do this, So I tried few libraries, MAPM :: very good performance, but it provides only big floats, with the possibility to

How can I represent a very large integer in .NET?

拈花ヽ惹草 提交于 2019-11-26 14:12:24
问题 Does .NET come with a class capable of representing extremely large integers, such as 100 factorial? If not, what are some good third party libraries to accomplish this? 回答1: .NET 4 has a BigInteger class Represents an arbitrarily large signed integer. The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. This type differs from the other integral types in the .NET Framework, which have a range indicated by

What is the difference between Int and Integer?

青春壹個敷衍的年華 提交于 2019-11-26 10:28:45
问题 In Haskell, what is the difference between an Int and an Integer ? Where is the answer documented? 回答1: "Integer" is an arbitrary precision type: it will hold any number no matter how big, up to the limit of your machine's memory…. This means you never have arithmetic overflows. On the other hand it also means your arithmetic is relatively slow. Lisp users may recognise the "bignum" type here. "Int" is the more common 32 or 64 bit integer. Implementations vary, although it is guaranteed to be

What is the standard (or best supported) big number (arbitrary precision) library for Lua?

孤街浪徒 提交于 2019-11-26 09:39:38
问题 I\'m working with large numbers that I can\'t have rounded off. Using Lua\'s standard math library, there seem to be no convenient way to preserve precision past some internal limit. I also see there are several libraries that can be loaded to work with big numbers: http://oss.digirati.com.br/luabignum/ http://www.tc.umn.edu/~ringx004/mapm-main.html http://lua-users.org/lists/lua-l/2002-02/msg00312.html (might be identical to #2) http://www.gammon.com.au/scripts/doc.php?general=lua_bc (but I

How to add 2 arbitrarily sized integers in C++?

∥☆過路亽.° 提交于 2019-11-26 08:57:14
问题 I would like to add 2 arbitrarily sized integers in C++. How can I go about doing this? 回答1: Here's an example showing how to use the OpenSSL bignum implementation for arbitrary-precision arithmetic. My example does 2 64 + 2 65 . I'm using Linux. #include <cstdio> #include <openssl/crypto.h> #include <openssl/bn.h> int main(int argc, char *argv[]) { static const char num1[] = "18446744073709551616"; static const char num2[] = "36893488147419103232"; BIGNUM *bn1 = NULL; BIGNUM *bn2 = NULL; BN

Working with large numbers in PHP

偶尔善良 提交于 2019-11-26 00:18:20
问题 To use modular exponentiation as you would require when using the Fermat Primality Test with large numbers (100,000+), it calls for some very large calculations. When I multiply two large numbers (eg: 62574 and 62574) PHP seems to cast the result to a float. Getting the modulus value of that returns strange values. $x = 62574 * 62574; var_dump($x); // float(3915505476) ... correct var_dump($x % 104659); // int(-72945) ... wtf. Is there any way to make PHP perform these calculations properly?

Arbitrary-precision arithmetic Explanation

醉酒当歌 提交于 2019-11-25 23:29:54
问题 I\'m trying to learn C and have come across the inability to work with REALLY big numbers (i.e., 100 digits, 1000 digits, etc.). I am aware that there exist libraries to do this, but I want to attempt to implement it myself. I just want to know if anyone has or can provide a very detailed, dumbed down explanation of arbitrary-precision arithmetic. 回答1: It's all a matter of adequate storage and algorithms to treat numbers as smaller parts. Let's assume you have a compiler in which an int can