13514
|
1 /*
|
|
2 * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. This
|
|
3 * code is released under a tri EPL/GPL/LGPL license. You can use it,
|
|
4 * redistribute it and/or modify it under the terms of the:
|
|
5 *
|
|
6 * Eclipse Public License version 1.0
|
|
7 * GNU General Public License version 2
|
|
8 * GNU Lesser General Public License version 2.1
|
|
9 */
|
|
10 package com.oracle.truffle.ruby.nodes.core;
|
|
11
|
|
12 import java.math.*;
|
|
13
|
|
14 import com.oracle.truffle.api.*;
|
|
15 import com.oracle.truffle.api.dsl.*;
|
|
16 import com.oracle.truffle.ruby.runtime.*;
|
|
17
|
|
18 @CoreClass(name = "Math")
|
|
19 public abstract class MathNodes {
|
|
20
|
|
21 @CoreMethod(names = "sqrt", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
|
|
22 public abstract static class SqrtNode extends CoreMethodNode {
|
|
23
|
|
24 public SqrtNode(RubyContext context, SourceSection sourceSection) {
|
|
25 super(context, sourceSection);
|
|
26 }
|
|
27
|
|
28 public SqrtNode(SqrtNode prev) {
|
|
29 super(prev);
|
|
30 }
|
|
31
|
|
32 @Specialization
|
|
33 public double sqrt(int a) {
|
|
34 return Math.sqrt(a);
|
|
35 }
|
|
36
|
|
37 @Specialization
|
|
38 public double sqrt(BigInteger a) {
|
|
39 return Math.sqrt(a.doubleValue());
|
|
40 }
|
|
41
|
|
42 @Specialization
|
|
43 public double sqrt(double a) {
|
|
44 return Math.sqrt(a);
|
|
45 }
|
|
46
|
|
47 }
|
|
48
|
|
49 @CoreMethod(names = "exp", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
|
|
50 public abstract static class ExpNode extends CoreMethodNode {
|
|
51
|
|
52 public ExpNode(RubyContext context, SourceSection sourceSection) {
|
|
53 super(context, sourceSection);
|
|
54 }
|
|
55
|
|
56 public ExpNode(ExpNode prev) {
|
|
57 super(prev);
|
|
58 }
|
|
59
|
|
60 @Specialization
|
|
61 public double exp(int a) {
|
|
62 return Math.exp(a);
|
|
63 }
|
|
64
|
|
65 @Specialization
|
|
66 public double exp(BigInteger a) {
|
|
67 return Math.exp(a.doubleValue());
|
|
68 }
|
|
69
|
|
70 @Specialization
|
|
71 public double exp(double a) {
|
|
72 return Math.exp(a);
|
|
73 }
|
|
74
|
|
75 }
|
|
76
|
|
77 }
|