Navigation Menu

Skip to content

Commit

Permalink
Add missing trig ops (via Math & Ops)
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Dec 31, 2012
1 parent 921bdb8 commit af474ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
26 changes: 2 additions & 24 deletions docs/LHF.md
@@ -1,34 +1,12 @@
# Low Hanging Fruit
Some (comparatively :-)) easy tasks for those who want to get involved.

## Add missing trig and numeric ops
The Math class in the Java Class Library only provides some of the trig ops
that we need directly. Those ones are already implemented. For the rest, add
implementations of them to the org.perl6.nqp.runtime.Ops class and update the
QAST compiler to know about them. The full list we should have is:

* sin_n
* asin_n
* cos_n
* acos_n
* tan_n
* atan_n
* atan2_n
* sec_n
* asec_n
* sin_n
* asin_n
* sinh_n
* cosh_n
* tanh_n
* sech_n

There are also some numeric ones missing:
## Add missing numeric ops

* gcd_i
* lcm_i

Add some tests for the things you add.
## Add tests for trig & numeric ops

## Bitwise ops
The integer bitwise ops are to do. They are:
Expand Down
6 changes: 6 additions & 0 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -693,6 +693,12 @@ QAST::OperationsJAST.map_classlib_core_op('acos_n', $TYPE_MATH, 'acos', [$RT_NUM
QAST::OperationsJAST.map_classlib_core_op('tan_n', $TYPE_MATH, 'tan', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('atan_n', $TYPE_MATH, 'atan', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('atan2_n', $TYPE_MATH, 'atan', [$RT_NUM, $RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('sinh_n', $TYPE_MATH, 'sinh', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('cosh_n', $TYPE_MATH, 'cosh', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('tanh_n', $TYPE_MATH, 'tanh', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('sec_n', $TYPE_OPS, 'sec_n', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('asec_n', $TYPE_OPS, 'asec_n', [$RT_NUM], $RT_NUM);
QAST::OperationsJAST.map_classlib_core_op('sech_n', $TYPE_OPS, 'sech_n', [$RT_NUM], $RT_NUM);

# aggregate opcodes
QAST::OperationsJAST.map_classlib_core_op('atpos', $TYPE_OPS, 'atpos', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);
Expand Down
15 changes: 14 additions & 1 deletion src/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -504,4 +504,17 @@ public static SixModelObject bindkey(SixModelObject arr, String key, SixModelObj
public static long elems(SixModelObject agg, ThreadContext tc) {
return agg.elems(tc);
}
}

/* Math operations. */
public static double sec_n(double val) {
return 1 / Math.cos(val);
}

public static double asec_n(double val) {
return Math.acos(1 / val);
}

public static double sech_n(double val) {
return 1 / Math.cosh(val);
}
}

0 comments on commit af474ba

Please sign in to comment.