Re:Bounded Integer: Header-only C++ library replaces integer...
by codewiz on Sunday September 29, 2019 @12:03PM
(#21107794)
But that performs very poorly on all architectures.
[ Parent
| on HN ]
Re:Bounded Integer: Header-only C++ library replaces integer...
by vzaliva on Sunday September 29, 2019 @12:39PM
(#21108028)
it does not have to. A smart compiler can narrow it down to machine size integers then possible.
Re:Bounded Integer: Header-only C++ library replaces integer...
by klyrs on Sunday September 29, 2019 @04:34PM
(#21109458)
> A smart compiler can narrow it down to machine size integers then possible.
A smart compiler will be able to narrow it down in a limited set of scenarios, but all we need to do is put an accumulator into a loop to see that bounding an integer is equivalent to the halting problem. Or for another example, should we expect our "smart" compiler to bound y in the following? The bound on x is a freebie.
bigint n(uint64_t x) {
bigint i = 0;
bigint y = x;
while (y != 1) {
i++;
if (y%2) y = y//2;
else y = 3*y-1;
}
return i;
}
Re:Bounded Integer: Header-only C++ library replaces integer...
by vzaliva on Sunday October 06, 2019 @12:40PM
(#21173083)
As I said, "when possible". When not possible a smart compiler can give a warning or an error and ask the user to either use arbirary-precision integer or a type with bound checking.
Re:Bounded Integer: Header-only C++ library replaces integer...
by klyrs on Sunday September 29, 2019 @08:45PM
(#21110783)
tfw you notice typos after the edit window closes :'(
Re:Bounded Integer: Header-only C++ library replaces integer...
by desertrider12 on Sunday September 29, 2019 @02:56PM
(#21108943)
In many situations yes, and C/C++ compilers miss a lot of opportunities for constant folding/propagation. But still, an infinitely smart compiler can’t prove anything about a value that comes from a file, user input or socket at runtime. If control flow depends on those (which is true of every useful real-life program) then you’re out of luck. GMP arbitrary-size integers are amazingly fast but still much slower than native instructions, can’t be vectorized, require heap allocation, etc.