-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.c
73 lines (60 loc) · 1.97 KB
/
math.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** @file Ficheiro que contém as funcionalidades relativas a operações aritmética */
#include <math.h>
#include "stack.h"
void sum(STACK *s) {
long double x = pop_operand(s),
y = pop_operand(s);
push_binary_operation(s, y + x);
}
void subtraction(STACK *s) {
long double x = pop_operand(s),
y = pop_operand(s);
push_binary_operation(s, y - x);
}
void multiplication(STACK *s) {
long double x = pop_operand(s),
y = pop_operand(s);
push_binary_operation(s, y * x);
}
void division(STACK *s) {
long double x = pop_operand(s),
y = pop_operand(s);
push_binary_operation(s, y / x);
}
void power(STACK *s) {
long double x = pop_operand(s),
y = pop_operand(s);
push_binary_operation(s, pow(y,x));
}
void module(STACK *s) {
int x = pop_INT(s),
y = pop_INT(s);
push_binary_operation(s, y % x);
}
void or_bitwise(STACK *s) {
int x = pop_INT(s),
y = pop_INT(s);
push_binary_operation(s, y | x);
}
void and_bitwise(STACK *s) {
int x = pop_INT(s),
y = pop_INT(s);
push_binary_operation(s, y & x);
}
void xor_bitwise(STACK *s) {
int x = pop_INT(s),
y = pop_INT(s);
push_binary_operation(s, y ^ x);
}
void not_bitwise(STACK *s) {
int x = pop_operand(s);
push_unary_operation(s, ~x);
}
void increment(STACK *s) {
double x = pop_operand(s);
push_unary_operation(s, x + 1);
}
void decrement(STACK *s){
double x = pop_operand(s);
push_unary_operation(s, x - 1);
}