Skip to content

Commit c3b4972

Browse files
committed
1.0.0-Beta4
1 parent b04f64e commit c3b4972

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/main/java/io/stack_community/github/stack_java/Functions.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.stack_community.github.stack_java;
22

33
import java.util.HashMap;
4+
import java.util.List;
5+
import java.util.Random;
46
import java.util.function.Supplier;
57

68
public class Functions {
@@ -70,7 +72,60 @@ public Functions(Stack.Executor executor) {
7072

7173
// Trigonometric sine
7274
addFunction("sin", (e) -> {
75+
double number = e.popStack().getNumber();
76+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.NUMBER, Math.sin(number)));
77+
});
78+
79+
// Trigonometric cosine
80+
addFunction("cos", (e) -> {
81+
double number = e.popStack().getNumber();
82+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.NUMBER, Math.cos(number)));
83+
});
84+
85+
// Trigonometric tangent
86+
addFunction("tan", (e) -> {
87+
double number = e.popStack().getNumber();
88+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.NUMBER, Math.tan(number)));
89+
});
90+
91+
// Logical operations of AND
92+
addFunction("and", (e) -> {
93+
boolean b = e.popStack().getBool();
94+
boolean a = e.popStack().getBool();
95+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.BOOL, a && b));
96+
});
97+
98+
// Logical operations of OR
99+
addFunction("or", (e) -> {
100+
boolean b = e.popStack().getBool();
101+
boolean a = e.popStack().getBool();
102+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.BOOL, a || b));
103+
});
104+
105+
// Logical operations of NOT
106+
addFunction("not", (e) -> {
107+
boolean a = e.popStack().getBool();
108+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.BOOL, !a));
109+
});
110+
111+
// Judge is it equal
112+
addFunction("equal", (e) -> {
113+
String b = e.popStack().getString();
114+
String a = e.popStack().getString();
115+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.BOOL, a.equals(b)));
116+
});
117+
118+
// Judge is it less
119+
addFunction("less", (e) -> {
120+
double b = e.popStack().getNumber();
121+
double a = e.popStack().getNumber();
122+
e.stack.add(new Stack.Type(Stack.Type.TypeEnum.BOOL, a < b));
123+
});
73124

125+
addFunction("rand", (e) -> {
126+
List<Stack.Type> list = e.popStack().getList();
127+
Stack.Type result = list.get(new Random().nextInt(list.size()));
128+
e.stack.add(result);
74129
});
75130

76131
// Commands of control

src/main/java/io/stack_community/github/stack_java/Stack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Stack {
99
public static String name = "Stack Programming Language: Java Edition";
1010
public static String baseVersion = "1.12";
11-
public static String version = "1.0.0-Beta";
11+
public static String version = "1.0.0-Beta4";
1212

1313
public Stack() {
1414

0 commit comments

Comments
 (0)