Hacker News new | ask | show | jobs
by gizmo686 4791 days ago
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.