Skip to content

Commit

Permalink
ceil, round and floor return integer-typed values
Browse files Browse the repository at this point in the history
unless the result is complex, in which case they still return a
'number'.

fixes #721
  • Loading branch information
christianp committed Jul 28, 2020
1 parent bdbdc16 commit 0dcc417
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 9 deletions.
33 changes: 30 additions & 3 deletions runtime/scripts/jme-builtins.js
Expand Up @@ -462,9 +462,36 @@ newBuiltin('coth', [TNum], TNum, math.coth );
newBuiltin('arcsinh', [TNum], TNum, math.arcsinh );
newBuiltin('arccosh', [TNum], TNum, math.arccosh );
newBuiltin('arctanh', [TNum], TNum, math.arctanh );
newBuiltin('ceil', [TNum], TNum, math.ceil );
newBuiltin('floor', [TNum], TNum, math.floor );
newBuiltin('round', [TNum], TNum, math.round );
newBuiltin('ceil', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.ceil(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('floor', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.floor(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('round', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.round(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('tonearest',[TNum,TNum], TNum, math.toNearest);
newBuiltin('trunc', [TNum], TNum, math.trunc );
newBuiltin('fract', [TNum], TNum, math.fract );
Expand Down
33 changes: 30 additions & 3 deletions tests/jme-runtime.js
Expand Up @@ -16623,9 +16623,36 @@ newBuiltin('coth', [TNum], TNum, math.coth );
newBuiltin('arcsinh', [TNum], TNum, math.arcsinh );
newBuiltin('arccosh', [TNum], TNum, math.arccosh );
newBuiltin('arctanh', [TNum], TNum, math.arctanh );
newBuiltin('ceil', [TNum], TNum, math.ceil );
newBuiltin('floor', [TNum], TNum, math.floor );
newBuiltin('round', [TNum], TNum, math.round );
newBuiltin('ceil', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.ceil(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('floor', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.floor(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('round', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.round(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('tonearest',[TNum,TNum], TNum, math.toNearest);
newBuiltin('trunc', [TNum], TNum, math.trunc );
newBuiltin('fract', [TNum], TNum, math.fract );
Expand Down
33 changes: 30 additions & 3 deletions tests/numbas-runtime.js
Expand Up @@ -11674,9 +11674,36 @@ newBuiltin('coth', [TNum], TNum, math.coth );
newBuiltin('arcsinh', [TNum], TNum, math.arcsinh );
newBuiltin('arccosh', [TNum], TNum, math.arccosh );
newBuiltin('arctanh', [TNum], TNum, math.arctanh );
newBuiltin('ceil', [TNum], TNum, math.ceil );
newBuiltin('floor', [TNum], TNum, math.floor );
newBuiltin('round', [TNum], TNum, math.round );
newBuiltin('ceil', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.ceil(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('floor', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.floor(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('round', [TNum], TNum, null, {
evaluate: function(args,scope) {
var n = math.round(jme.castToType(args[0],'number').value);
if(n.complex) {
return new TNum(n);
} else {
return new TInt(n);
}
}
});
newBuiltin('tonearest',[TNum,TNum], TNum, math.toNearest);
newBuiltin('trunc', [TNum], TNum, math.trunc );
newBuiltin('fract', [TNum], TNum, math.fract );
Expand Down

0 comments on commit 0dcc417

Please sign in to comment.