Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for bignums? #1463

Closed
jakub-gonet opened this issue Jan 8, 2025 · 3 comments
Closed

Support for bignums? #1463

jakub-gonet opened this issue Jan 8, 2025 · 3 comments

Comments

@jakub-gonet
Copy link
Contributor

I couldn't find the limitations section in the docs.

  1. Is bignum support considered?
  2. Would you accept a patch for externalterm to have better error reporting when it can't decode serialized data?

AVM communicate well enough if value is out of bounds in runtime but does pretty poor error reporting if loaded BEAM file has it as a literal:

if (UNLIKELY(num_bytes > 8 || remaining < (SMALL_BIG_EXT_BASE_SIZE + num_bytes))) {
return INVALID_TERM_SIZE;
}

This aborts the VM (module_load_literal).

Example code:

-module(hello_world).
-export([
    start/0,
    is_bignum/1
]).

start() ->
    erlang:display(?MODULE:is_bignum(1)),
    ok.

% crashes the VM
is_bignum(N) ->
    if
        N >= 1 bsl 128 ->
            big;
        N =< -(1 bsl 128) ->
            smol;
        true ->
            ok
    end.

%% dumps VM state
% is_bignum(N) ->
%     Big = rt_bsl(1, 128),
%     Smol = -rt_bsl(1, 128),
%     if
%         N >= Big ->
%             big;
%         N =< Smol ->
%             smol;
%         true ->
%             ok
%     end.

% rt_bsl(N, 0) -> N;
% rt_bsl(N, Shift) -> rt_bsl(2 * N, Shift - 1).
@jakub-gonet
Copy link
Contributor Author

Actually, duplicate of #1345.

@UncleGrumpy
Copy link
Collaborator

I couldn't find the limitations section in the docs.

  1. Is bignum support considered?

This should probably be up front in the introductory section of the docs, but for reference, bignums are covered in the "Limitations" section of the Programmer's Guide:

https://www.atomvm.net/doc/main/programmers-guide.html#limitations

@jakub-gonet
Copy link
Contributor Author

I'll update the other comment. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants