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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* MIT License
*
* Copyright (c) 2023 Christian Chapman
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "calc.h"
// Stack and register control
int calc_delete(calc_state_t *cs);
int calc_clear_stack(calc_state_t *cs);
int calc_flip(calc_state_t *cs);
int calc_mem_clear(calc_state_t *cs);
int calc_mem_recall(calc_state_t *cs);
int calc_mem_add(calc_state_t *cs);
int calc_mem_subtract(calc_state_t *cs);
// Basic operations
int calc_add(calc_state_t *cs);
int calc_subtract(calc_state_t *cs);
int calc_negate(calc_state_t *cs);
int calc_multiply(calc_state_t *cs);
int calc_divide(calc_state_t *cs);
int calc_invert(calc_state_t *cs);
// Constants
int calc_e(calc_state_t *cs);
int calc_pi(calc_state_t *cs);
// Exponential/logarithmic
int calc_exp(calc_state_t *cs);
int calc_pow(calc_state_t *cs);
int calc_ln(calc_state_t *cs);
int calc_log(calc_state_t *cs);
int calc_sqrt(calc_state_t *cs);
// Trigonometric
int calc_sin(calc_state_t *cs);
int calc_cos(calc_state_t *cs);
int calc_tan(calc_state_t *cs);
int calc_asin(calc_state_t *cs);
int calc_acos(calc_state_t *cs);
int calc_atan(calc_state_t *cs);
int calc_atan2(calc_state_t *cs);
int calc_sind(calc_state_t *cs);
int calc_cosd(calc_state_t *cs);
int calc_tand(calc_state_t *cs);
int calc_asind(calc_state_t *cs);
int calc_acosd(calc_state_t *cs);
int calc_atand(calc_state_t *cs);
int calc_atan2d(calc_state_t *cs);
// Dictionary definition
typedef int (*calc_fn_t)(calc_state_t *cs);
typedef struct {
char *names[3]; // Token to use to run this function
calc_fn_t fn; // Pointer to function
} calc_dict_entry_t;
static const calc_dict_entry_t calc_dict[] = {
// Stack and register control
{{"x"}, &calc_delete},
{{"xx"}, &calc_clear_stack},
{{"xxx"}, &calc_init},
{{"f"}, &calc_flip},
{{"mc"}, &calc_mem_clear},
{{"mr"}, &calc_mem_recall},
{{"ma"}, &calc_mem_add},
{{"ms"}, &calc_mem_subtract},
// Basic operations
{{"a"}, &calc_add},
{{"s"}, &calc_subtract},
{{"n"}, &calc_negate},
{{"m"}, &calc_multiply},
{{"d"}, &calc_divide},
{{"i"}, &calc_invert},
// Constants
{{"e"}, &calc_e},
{{"pi"}, &calc_pi},
// Exponential/logarithmic
{{"exp"}, &calc_exp},
{{"pow"}, &calc_pow},
{{"ln"}, &calc_ln},
{{"log"}, &calc_log},
{{"sqrt"}, &calc_sqrt},
// Trigonometric
{{"sin", "sn"}, &calc_sin},
{{"cos"}, &calc_cos},
{{"tan"}, &calc_tan},
{{"asin"}, &calc_asin},
{{"acos"}, &calc_acos},
{{"atan"}, &calc_atan},
{{"atan2"}, &calc_atan2},
{{"sind"}, &calc_sind},
{{"cosd"}, &calc_cosd},
{{"tand"}, &calc_tand},
{{"asind"}, &calc_asind},
{{"acosd"}, &calc_acosd},
{{"atand"}, &calc_atand},
{{"atan2d"}, &calc_atan2d},
};
|