http://qs321.pair.com?node_id=887172


in reply to Re^6: Module for 128-bit integer math?
in thread Module for 128-bit integer math?

Does int128() and uint128() croak for "0400000000000000000000000000000000000000"?

It should now ;-)

Does $x + undef and the like warn?

yes

(Note that «undef + $x» cannot warn without making «my $x; $x += int128(...)» warn.)
Operations with undefs always generate warnings. Emulating the Perl behavior for built-ins up to this level is not one of my targets.
Does signed to unsigned promotion occur when required? (e.g. when adding two a large number overflows.)

Does unsigned to signed promotion occur when required? (e.g. when subtraction overflows to something negative.)

No, automatic promotions would just complicate the semantics of the module too much. Currently, the module provides modulo 2**128 signed and unsigned arithmetic and the semantics are pretty simple:

Are the string buffers always suitably aligned for a int128_t? (You use memcpy in some spots, but casts in others.)

Internally 128bit values are stored on the stack or on the PV slot of an SV allocated with newSV(16). As GCC seems to use 64bit instructions to load 128 bits integers from memory, alignment should be right.