Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[js] Implement nqp::{sinh,cosh,tanh,atan2,sec,asec,sech}_n ops.
  • Loading branch information
pmurias committed Mar 9, 2016
1 parent cc3b913 commit 8f82c9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/vm/js/Operations.nqp
Expand Up @@ -736,10 +736,16 @@ class QAST::OperationsJS {

add_simple_op('existspos', $T_BOOL, [$T_OBJ, $T_INT]);

for <ceil floor abs log sqrt exp sin acos cos atan tan asin> -> $func {
for <ceil floor abs log sqrt exp sin acos cos atan tan asin sinh cosh tanh> -> $func {
add_simple_op($func ~ '_n', $T_NUM, [$T_NUM], sub ($arg) {"Math.$func($arg)"});
}

add_simple_op('atan2_n', $T_NUM, [$T_NUM, $T_NUM], sub ($y, $x) {"Math.atan2($y, $x)"});

add_simple_op('sec_n', $T_NUM, [$T_NUM]);
add_simple_op('asec_n', $T_NUM, [$T_NUM]);
add_simple_op('sech_n', $T_NUM, [$T_NUM]);

add_simple_op('abs_i', $T_INT, [$T_INT], sub ($arg) {"Math.abs($arg)"});
add_simple_op('pow_n', $T_NUM, [$T_NUM, $T_NUM], sub ($base, $exponent) {"Math.pow($base, $exponent)"});

Expand Down
12 changes: 12 additions & 0 deletions src/vm/js/nqp-runtime/core.js
Expand Up @@ -773,6 +773,18 @@ op.mod_n = function(a, b) {
return a - Math.floor(a / b) * b;
};

op.sec_n = function(x) {
return 1 / Math.cos(x);
};

op.asec_n = function(x) {
return Math.acos(1 / x);
};

op.sech_n = function(x) {
return (2 * Math.cosh(x)) / (Math.cosh(2 * x) + 1);
};

op.isnanorinf = function(n) {
return (isNaN(n) || n == Infinity || n == -Infinity) ? 1 : 0;
};
Expand Down

0 comments on commit 8f82c9a

Please sign in to comment.