Hacker News new | ask | show | jobs
by omra 4791 days ago
a) That solution is sometimes implanted. The problem is: its slow, very, very, slow. It is not nearly as fast as regular integer arithmetic. (Also, +, -, /, and * aren't called axioms.) Also, how do you handle things such as powers and exponentiation (especially non-integer arguments)?

b) Search up for "BigInt libraries". The problem is the same with the others, its slow. You still have to allocate memory and the operations aren't as fast. However, BigInt libraries are widely used when necessary.

2 comments

@omra, why downvote a question? It wasn't a proposed solution to the problem, it was a question on if there is a solution similar to that and otherwise why this would be wrong. I have added that I believe that this would be slow, if you read it carefully.

Btw. "axiom" was probably an unlucky translation of "Körperaxiom". See: http://de.wikipedia.org/wiki/K%C3%B6rper_%28Algebra%29 The english wikipedia says:

"The most common way to formalize this is by defining a field as a set together with two operations, usually called addition and multiplication, and denoted by + and ·, respectively, such that the following axioms hold; subtraction and division are defined implicitly in terms of the inverse operations of addition and multiplication"

omra likely did not downvote your question.
Are (well implemented) BigInt libraries actually significantly slower in the cases where the underlying primitive is large enough.

For example, say it is implemented as a singly-linked-list of ints. The input to the addition function is a pointer to the heads of 2 BigInts. To do the addition:

Dereference the 2 pointers. Perform the primitive addition. Check the overflow bit Check the 2 'next' pointers. if(hasNext OR overflow) ...

Assuming normal ints would suffice, (hasNext OR overflow) would be false, so you are done. Also, if it is always false, then branch prediction would guess correctly here.