A shame that this is so C-specific; most of the bugs seem to be trivialities around C integer behaviour that simply wouldn't be an issue in e.g. Python. So it would be good to see comparisons to other languages.
Why don't we have any languages where small bignums are as fast as fixnums? Is it a hardware problem (difficult to have an overflow trap with zero cost in case of no overflow), or is it a programming problem?
Theoretically they're supposed to be (in practice it's hard to tell given how slow the rest of the language is and so I wouldn't be surprised if there were undiscovered implementation issues, but they should be). The case where you do trap an overflow and redo the calculation with bignums is of course a bit slower than doing it with bignums in the first place so it's not a completely free lunch (though AIUI the bignum calculation takes substantially longer than the trapped attempt at doing it with fixnums so it doesn't really matter).
AIUI trapping on overflow is usually supported at the hardware level, so it's no overhead unless an overflow actually happens. (This is outside my area of expertise though - it's possible I'm wrong and they have to explicitly check the carry flag or some such, at least on some platforms)
Of course, in Python this is also pretty trivial to write. You just do the two illegality checks, then if you get through those "return len(set((a, b, c)))" will be the correct result.
10 comments
[ 3.0 ms ] story [ 26.8 ms ] threadWhy don't we have any languages where small bignums are as fast as fixnums? Is it a hardware problem (difficult to have an overflow trap with zero cost in case of no overflow), or is it a programming problem?