arbitrary-precision

How can I use arbitrary length integers in Perl?

痞子三分冷 提交于 2020-01-01 09:25:10
问题 Is there any standard way to use integers of arbitrary length in Perl? I am working on code that generates x64 assembly for tests, and I'm tired of manipulating 32 bits at a time. I'm using Perl 5.10.0, for what it's worth. 回答1: If you only want to use big integers, you can use the bigint , which you can scope to a file: use bigint; or just a limited scope: { use bigint; ...; } If you need big floating point numbers as well as big integers, you can use the bignum pragma in the same way.

Convert large hex string to decimal string

ε祈祈猫儿з 提交于 2019-12-29 06:21:11
问题 I need to convert a large (too large for the built-in data types) hex string to a string with it's decimal representation. For example: std::string sHex = "07AA17C660F3DD1D2A1B48F1B746C148"; std::string sDec; // should end up with: "10187768649047767717933300899576725832" I'm currently using the c++ BigInt Class which offers a very easy way to achieve this (but is GPL only): BigInt::Vin vbiTemp(sHex, 16); sDec = vbiTemp.toStrDec(); Is there simple way to do this conversion without a 3rd party

x86-64 Big Integer Representation?

♀尐吖头ヾ 提交于 2019-12-29 01:16:07
问题 How do hig-performance native big-integer libraries on x86-64 represent a big integer in memory? (or does it vary? Is there a most common way?) Naively I was thinking about storing them as 0-terminated strings of numbers in base 2 64 . For example suppose X is in memory as: [8 bytes] Dn . . [8 bytes] D2 [8 bytes] D1 [8 bytes] D0 [8 bytes] 0 Let B = 2 64 Then X = D n * B n + ... + D 2 * B 2 + D 1 * B 1 + D 0 The empty string (i.e. 8 bytes of zero) means zero. Is this a reasonable way? What are

What class to use for money representation?

安稳与你 提交于 2019-12-28 06:28:24
问题 What class should I use for representation of money to avoid most rounding errors? Should I use Decimal , or a simple built-in number ? Is there any existing Money class with support for currency conversion that I could use? Any pitfalls that I should avoid? 回答1: I assume that you talking about Python. http://code.google.com/p/python-money/ "Primitives for working with money and currencies in Python" - the title is self explanatory :) 回答2: Never use a floating point number to represent money.

What class to use for money representation?

ぐ巨炮叔叔 提交于 2019-12-28 06:28:02
问题 What class should I use for representation of money to avoid most rounding errors? Should I use Decimal , or a simple built-in number ? Is there any existing Money class with support for currency conversion that I could use? Any pitfalls that I should avoid? 回答1: I assume that you talking about Python. http://code.google.com/p/python-money/ "Primitives for working with money and currencies in Python" - the title is self explanatory :) 回答2: Never use a floating point number to represent money.

numpy arbitrary precision linear algebra

你。 提交于 2019-12-28 02:10:30
问题 I have a numpy 2d array [medium/large sized - say 500x500]. I want to find the eigenvalues of the element-wise exponent of it. The problem is that some of the values are quite negative (-800,-1000, etc), and their exponents underflow (meaning they are so close to zero, so that numpy treats them as zero). Is there anyway to use arbitrary precision in numpy? The way I dream it: import numpy as np np.set_precision('arbitrary') # <--- Missing part a = np.array([[-800.21,-600.00],[-600.00,-1000.48

Arbitrary precision bit manipulation (Objective C)

和自甴很熟 提交于 2019-12-25 18:12:40
问题 I need to do bit operations on representations of arbitrary precision numbers in Objective C. So far I have been using NSData objects to hold the numbers - is there a way to bit shift the content of those? If not, is there a different way to achieve this? 回答1: Using NSMutableData you can fetch the byte in a char , shift your bits and replace it with -replaceBytesInRange:withBytes: . I don't see any other solution except for writing your own date holder class using a char * buffer to hold the

implementing a bignum library for rsa encryption

ぃ、小莉子 提交于 2019-12-24 08:29:14
问题 So of course I know there are simple solutions to this such as using the GMP library or numerous other arbitrary-precision libraries. This is for class work so I am not allowed to take any of these routes. After we build up all our operations we are leading up to be able to do a RSA encryption scheme. I am using vectors to store n-bit numbers represented in binary. I have conversions to decimal later but I must operate on the binary and only convert for display. I have successfully

Boost multiprecision fails because the implementation of complex tries to cast to double in internal functions like _Isinf or _Isnan

♀尐吖头ヾ 提交于 2019-12-23 09:58:13
问题 I need a BSD-like licensed C(++) multiprecision library with complex numbers support so I tried boost. The following code fails: #include <boost/multiprecision/cpp_dec_float.hpp> #include <complex> using namespace boost::multiprecision; std::complex<cpp_dec_float_50>(1.0, 2.0) / std::complex<cpp_dec_float_50>(1.0, 2.0) in Visual Studio 2012 with an error C2440 because the implementation of complex tries to cast to double in internal functions like _Isinf or _Isnan. Is this an error on my part

Big Integer addition, I know the theory… still rusty in practice

烂漫一生 提交于 2019-12-22 10:45:37
问题 so, I'm trying to build a simple big integer class, I've read some pages on the internet and all that, but I'm stuck. I know the theory and I know that I need a carry but all examples I've seen, they focuded more in chars and in base 10 and well, I'm using a different approach to make it a bit more faster. I would appreciate some help with the plus assignment operator, the rest of it I'll try to figure it out by myself. #include <iostream> #include <string> #include <vector> using std::cout;