Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/javascript/lib/core/erlang_compat/erlang.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function equals(left, right) {
}

function div(left, right) {
return left / right;
return Math.trunc(left / right);
}

function not(x) {
Expand Down Expand Up @@ -357,7 +357,7 @@ function min(first, second) {
}

function round(number) {
return Math.round(number);
return Math.sign(number) * Math.round(Math.abs(number));
}

function tl(list) {
Expand Down Expand Up @@ -463,7 +463,6 @@ function nodes(arg = []) {
for (const nodeType of nodeTypes) {
if (nodeType === Symbol.for('this')) {
nodesFound.push(Symbol.for('nonode@nohost'));
console.log(nodesFound);
}
}
return nodesFound;
Expand Down
30 changes: 30 additions & 0 deletions src/javascript/tests/core/erlang_compat/erlang_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ test('list_subtraction', (t) => {
t.deepEqual(Core.erlang.list_subtraction([1, 2, 3], [1, 2]), [3]);
});

test('div', (t) => {
t.is(Core.erlang.div(6, 3), 2);
t.is(Core.erlang.div(7, 2), 3);
t.is(Core.erlang.div(-7, 2), -3);
t.is(Core.erlang.div(7, -2), -3);
t.is(Core.erlang.div(-7, -2), 3);
});

test('rem', (t) => {
t.is(Core.erlang.rem(7, 2), 1);
t.is(Core.erlang.rem(-7, 2), -1);
t.is(Core.erlang.rem(7, -2), 1);
t.is(Core.erlang.rem(-7, -2), -1);
});

test('round', (t) => {
t.is(Core.erlang.round(1.4), 1);
t.is(Core.erlang.round(2.5), 3);
t.is(Core.erlang.round(-2.5), -3);
t.is(Core.erlang.round(0.5), 1);
t.is(Core.erlang.round(-0.5), -1);
t.is(Core.erlang.round(4), 4);
t.is(Core.erlang.round(-4), -4);
});

test('trunc', (t) => {
t.is(Core.erlang.trunc(2.7), 2);
t.is(Core.erlang.trunc(-2.7), -2);
});

test('node', (t) => {
t.deepEqual(Core.erlang.node(), Symbol.for('nonode@nohost'));
});
Expand Down