Skip to content

Commit 33736a0

Browse files
committed
Workaround for unsupported 'short' option in :erlang.float_to_list (#166)
fixes software-mansion/popcorn#425 This PR brings back #150, missed when downstreaming
1 parent 01df099 commit 33736a0

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/libAtomVM/nifs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,13 @@ int get_float_format_opts(term opts, int *scientific, int *decimals, int *compac
25522552
} else if (head == DEFAULTATOMS_COMPACT_ATOM) {
25532553
*compact = 1;
25542554

2555+
} else if (head == SHORT_ATOM) {
2556+
// FIXME: OTP uses ryu algorithm for short format,
2557+
// vendored as a lib (https://github.com/erlang/otp/tree/master/erts/emulator/ryu)
2558+
// Workaround here uses default decimal precision with compacting
2559+
*scientific = 0;
2560+
*decimals = 10;
2561+
*compact = 1;
25552562
} else {
25562563
return 0;
25572564
}

src/libAtomVM/popcorn/popcorn_atoms.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ X(TRIM_ALL_ATOM, "\x8", "trim_all")
33
X(STDOUT_ATOM, "\x6", "stdout")
44
X(STDERR_ATOM, "\x6", "stderr")
55
X(NIF_NOT_FOUND_ERROR_ATOM, "\x13", "nif_not_found_error")
6+
X(SHORT_ATOM, "\x5", "short")

0 commit comments

Comments
 (0)