otp icon indicating copy to clipboard operation
otp copied to clipboard

erlang: Add int/1 and uint/1 as built-in types

Open jhogberg opened this issue 1 month ago • 4 comments

This PR adds convenience types for expressing integers of a certain width and signedness, letting us remove ad-hoc definitions in various places.

jhogberg avatar Nov 27 '25 14:11 jhogberg

CT Test Results

    5 files    252 suites   2h 6m 50s ⏱️ 4 114 tests 4 010 ✅ 103 💤 1 ❌ 5 251 runs  5 122 ✅ 128 💤 1 ❌

For more details on these failures, see this check.

Results for commit 8d3e421e.

:recycle: This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

github-actions[bot] avatar Nov 27 '25 14:11 github-actions[bot]

I'm not sure those types are particularly useful by themselves. There's nothing that guarantees any operation on an int(32) type will be within bounds - e.g. adding two int(32) can easily over- or underflow and exceed the range. This means the types are effectively only useful for literals and can't be easily enforced.

If we really wanted this, I think it should be paired with some sort of int module that supports fixed-size integer operations.

michalmuskala avatar Nov 27 '25 15:11 michalmuskala

Of course, this is just to standardize on a type instead of having lots of ad-hoc ones in socket, rand, etc.

jhogberg avatar Nov 27 '25 15:11 jhogberg

This is just a much more convenient and readable way to write for example -16#7FFF_FFFF..16#7FFF_FFFE as int(32) instead. It will really improve readability for many socket options in socket, as well as in many other modules that deal with protocols and interfacing.

RaimoNiskanen avatar Nov 28 '25 07:11 RaimoNiskanen