arbitrary-precision

SIMD versions of SHLD/SHRD instructions

你离开我真会死。 提交于 2019-11-30 20:44:18
SHLD/SHRD instructions are assembly instructions to implement multiprecisions shifts. Consider the following problem: uint64_t array[4] = {/*something*/}; left_shift(array, 172); right_shift(array, 172); What is the most efficient way to implement left_shift and right_shift , two functions that operates a shift on an array of four 64-bit unsigned integer as if it was a big 256 bits unsigned integer? Is the most efficient way of doing that is by using SHLD/SHRD instructions, or is there better (like SIMD versions) instructions on modern architecture? In this answer I'm only going to talk about

Arbitrary-Precision Math in PHP

一笑奈何 提交于 2019-11-30 17:48:55
I'm currently trying to figure out how to work with arbitrary-precision numbers in PHP. So I guess my first question would be what exactly is arbitrary-precision math. I tried Googling for a good definition but for some reason nobody can put it in simple enough words. Second, what are the differences between the BCMath and GMP libraries in PHP? I've heard claims that GMP's API is "fresher", but idk. Is one better? And my final question would be what type of numbers BCMath/GMP takes. Obviously it takes normal integers in string form (e.g. "5.34"), but I've seen implementations where BCMath

What is the sum of the digits of the number 2^1000?

ⅰ亾dé卋堺 提交于 2019-11-30 12:49:13
This is a problem from Project Euler , and this question includes some source code, so consider this your spoiler alert, in case you are interested in solving it yourself. It is discouraged to distribute solutions to the problems, and that isn't what I want. I just need a little nudge and guidance in the right direction, in good faith. The problem reads as follows: 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? I understand the premise and math of the problem, but I've only started practicing C# a week ago, so my

What is the sum of the digits of the number 2^1000?

帅比萌擦擦* 提交于 2019-11-29 18:02:20
问题 This is a problem from Project Euler, and this question includes some source code, so consider this your spoiler alert, in case you are interested in solving it yourself. It is discouraged to distribute solutions to the problems, and that isn't what I want. I just need a little nudge and guidance in the right direction, in good faith. The problem reads as follows: 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? I understand

arbitrary precision addition using lists of digits

妖精的绣舞 提交于 2019-11-29 17:57:19
What I'm trying to do is take two lists and add them together like each list is a whole number. (define (reverse lst) (if (null? lst) '() (append (reverse (cdr lst)) (list (car lst))))) (define (apa-add l1 l2) (define (apa-add-help l1 l2) (cond ((and (null? l1) (null? l2)) '()) ((null? l1) (list (+ (apa-add-help '() (cdr l2))))) ((null? l2) (list (+ (apa-add-help (cdr l1) '())))) ((>= (+ (car l1) (car l2)) 10) (append (apa-add-help (cdr l1) (cdr l2)) (list (quotient (+ (car l1) (car l2)) 10)) (list (modulo (+ (car l1) (car l2)) 10)))) ;this is a problem (else (append (apa-add-help (cdr l1)

Logarithm of the very-very large number

亡梦爱人 提交于 2019-11-29 15:28:37
I have to find log of very large number. I do this in C++ I have already made a function of multiplication, addition, subtraction, division, but there were problems with the logarithm. I do not need code, I need a simple idea how to do it using these functions. Thanks. P.S. Sorry, i forgot to tell you: i have to find only binary logarithm of that number P.S.-2 I found in Wikipedia : int floorLog2(unsigned int n) { if (n == 0) return -1; int pos = 0; if (n >= (1 <<16)) { n >>= 16; pos += 16; } if (n >= (1 << 8)) { n >>= 8; pos += 8; } if (n >= (1 << 4)) { n >>= 4; pos += 4; } if (n >= (1 << 2))