arbitrary-precision

Handle arbitrary length integers in C++

China☆狼群 提交于 2019-11-27 03:55:07
问题 Can someone tell me of a good C++ library for handling (doing operations etc...) with arbitrarily large numbers (it can be a library that handles arbitrary precision floats too, but handling integers is more important)? Please only refer to libraries that YOU used and tell me how did you managed to set it up and pick it up, maybe with a very minimalistic example or something (basically if the mentioned library lacks good documentation provide some input of your own). For the record I'm using

Large numbers in Pascal (Delphi)

陌路散爱 提交于 2019-11-27 03:52:43
问题 Can I work with large numbers (more than 10^400) with built-in method in Delphi? 回答1: Not built-in, but you might want to check out MPArith for arbitrary precision maths. 回答2: There is also a Delphi BigInt library on SourceForge . I haven't tried it however, but include for completeness. 回答3: You could implement your own large number routines using Delphi's operator overloading. For example add, subtract, multiply and division. Intel has also added new instructions for multiply and possibly

Python and “arbitrary precision integers”

风流意气都作罢 提交于 2019-11-26 21:14:24
问题 Python is supposed to have "arbitrary precision integers," according to the answer in Python integer ranges. But this result is plainly not arbitrary precision: $ python -c 'print("%d" % (999999999999999999999999/3))' 333333333333333327740928 According to PEP 237, bignum is arbitrarily large (not just the size of C's long type). And Wikipedia says Python's bignum is arbitrary precision. So why the incorrect result from the above line of code? 回答1: Actually in python3 whenever you divide ints

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

感情迁移 提交于 2019-11-26 19:05:43
I would like to add 2 arbitrarily sized integers in C++. How can I go about doing this? 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_CTX *ctx = BN_CTX_new(); BN_dec2bn(&bn1, num1); // convert the string to BIGNUM BN_dec2bn(&bn2, num2); BN

How to generate random 64-bit value as decimal string in PHP

倖福魔咒の 提交于 2019-11-26 19:02:47
Oauth requires a random 64-bit, unsigned number encoded as an ASCII string in decimal format. Can you guys help me achieve this with php? Thanks You could use two 32-bit numbers, four 16-bit numbers, etc. PHP has rand() and and mt_rand() but how many random bits they supply isn't specified by the standard (though they can be queried with the help of getrandmax() and mt_getrandmax() , respectively.) So your safest simplest bet would be generating 64 random bits and setting them one by one. As for working with 64-bit integers, I'd recommend using the GMP library as it has a good range of

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

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

Hash an arbitrary precision value (boost::multiprecision::cpp_int)

折月煮酒 提交于 2019-11-26 08:36:46
问题 I need to get the hash of value with arbitrary precision (from Boost.Multiprecision); I use the cpp_int backend. For now, I came up with the following code: boost::multiprecision::cpp_int x0 = 1; const auto seed = std::hash<std::string>{}(x0.str()); I don\'t need the code to be as fast as possible, but I find it very clumsy to hash the string representation. So my question is twofold: Keeping the arbitrary precision, can I hash the value more efficiently? Maybe I should not insisting on

How to generate random 64-bit value as decimal string in PHP

女生的网名这么多〃 提交于 2019-11-26 06:45:24
问题 Oauth requires a random 64-bit, unsigned number encoded as an ASCII string in decimal format. Can you guys help me achieve this with php? Thanks 回答1: You could use two 32-bit numbers, four 16-bit numbers, etc. PHP has rand() and and mt_rand() but how many random bits they supply isn't specified by the standard (though they can be queried with the help of getrandmax() and mt_getrandmax(), respectively.) So your safest simplest bet would be generating 64 random bits and setting them one by one.