702ad47e77dd696f5f1707c52e2a9f5a6225704f
[reactos.git] / base / applications / calc / calc.h
1 #ifndef _CALC_H
2 #define _CALC_H
3
4 #include <stdarg.h>
5 #include <windef.h>
6 #include <winuser.h>
7 #include <tchar.h>
8 #include <math.h>
9 #include <float.h>
10 #include <malloc.h>
11 #ifndef DISABLE_HTMLHELP_SUPPORT
12 #include <htmlhelp.h>
13 #endif
14 #include <limits.h>
15
16 /* Messages reserved for the main dialog */
17 #define WM_CLOSE_STATS (WM_APP+1)
18 #define WM_HANDLE_CLIPBOARD (WM_APP+2)
19 #define WM_INSERT_STAT (WM_APP+3)
20 #define WM_LOAD_STAT (WM_APP+4)
21 #define WM_START_CONV (WM_APP+5)
22 #define WM_HANDLE_FROM (WM_APP+6)
23 #define WM_HANDLE_TO (WM_APP+7)
24
25 /* GNU MULTI-PRECISION LIBRARY support */
26 #ifdef ENABLE_MULTI_PRECISION
27 #include "mpfr.h"
28
29 #ifndef MPFR_DEFAULT_RND
30 #define MPFR_DEFAULT_RND mpfr_get_default_rounding_mode ()
31 #endif
32
33 #define LOCAL_EXP_SIZE 100000000L
34 #else
35
36 #define LOCAL_EXP_SIZE 10000L
37
38 #endif
39
40 #include "resource.h"
41
42 #ifndef IDC_STATIC
43 #define IDC_STATIC ((DWORD)-1)
44 #endif
45
46 #define MAX_CALC_SIZE 256
47
48 /*#define USE_KEYBOARD_HOOK*/
49
50 #define SIZEOF(_ar) (sizeof(_ar)/sizeof(_ar[1]))
51
52 // RPN.C
53
54 enum {
55 RPN_OPERATOR_PARENT,
56 RPN_OPERATOR_PERCENT,
57 RPN_OPERATOR_EQUAL,
58
59 RPN_OPERATOR_OR,
60 RPN_OPERATOR_XOR,
61 RPN_OPERATOR_AND,
62 RPN_OPERATOR_LSH,
63 RPN_OPERATOR_RSH,
64 RPN_OPERATOR_ADD,
65 RPN_OPERATOR_SUB,
66 RPN_OPERATOR_MULT,
67 RPN_OPERATOR_DIV,
68 RPN_OPERATOR_MOD,
69 RPN_OPERATOR_POW,
70 RPN_OPERATOR_SQR,
71
72 RPN_OPERATOR_NONE
73 };
74
75 typedef union {
76 #ifdef ENABLE_MULTI_PRECISION
77 mpfr_t mf;
78 #else
79 double f;
80 INT64 i;
81 UINT64 u;
82 #endif
83 } calc_number_t;
84
85 typedef struct {
86 calc_number_t number;
87 unsigned int operation;
88 DWORD base;
89 } calc_node_t;
90
91 void run_operator(calc_node_t *result, calc_node_t *a,
92 calc_node_t *b, unsigned int operation);
93 int exec_infix2postfix(calc_number_t *, unsigned int);
94 void exec_closeparent(calc_number_t *);
95 int eval_parent_count(void);
96 void flush_postfix(void);
97 void exec_change_infix(void);
98 void start_rpn_engine(void);
99 void stop_rpn_engine(void);
100
101 typedef struct {
102 char *data;
103 char *ptr;
104 UINT wm_msg;
105 } sequence_t;
106
107 typedef struct {
108 calc_number_t num;
109 DWORD base;
110 void *next;
111 } statistic_t;
112
113 enum {
114 CALC_LAYOUT_SCIENTIFIC=0,
115 CALC_LAYOUT_STANDARD,
116 CALC_LAYOUT_CONVERSION,
117 };
118
119 typedef struct {
120 HINSTANCE hInstance;
121 #ifdef USE_KEYBOARD_HOOK
122 HHOOK hKeyboardHook;
123 #endif
124 HWND hWnd;
125 DWORD layout;
126 TCHAR buffer[MAX_CALC_SIZE];
127 TCHAR source[MAX_CALC_SIZE];
128 TCHAR *ptr;
129 calc_number_t code;
130 calc_number_t prev;
131 calc_node_t memory;
132 statistic_t *stat;
133 BOOL is_memory;
134 BOOL is_nan;
135 BOOL sci_out;
136 BOOL sci_in;
137 BOOL usesep;
138 BOOL is_menu_on;
139 signed int esp;
140 DWORD base;
141 DWORD size;
142 DWORD degr;
143 DWORD action;
144 HWND hStatWnd;
145 HWND hConvWnd;
146 sequence_t Clipboard;
147 sequence_t Convert[2];
148 unsigned int last_operator;
149 unsigned int prev_operator;
150 TCHAR sDecimal[8];
151 TCHAR sThousand[8];
152 unsigned int sDecimal_len;
153 unsigned int sThousand_len;
154 signed int x_coord;
155 signed int y_coord;
156 } calc_t;
157
158 extern calc_t calc;
159
160 /* IEEE constants */
161 #define CALC_E 2.718281828459045235360
162 #define CALC_PI_2 1.570796326794896619231
163 #define CALC_PI 3.141592653589793238462
164 #define CALC_3_PI_2 4.712388980384689857694
165 #define CALC_2_PI 6.283185307179586476925
166
167 #define MODIFIER_INV 0x01
168 #define MODIFIER_HYP 0x02
169 #define NO_CHAIN 0x04
170
171 void apply_int_mask(calc_number_t *a);
172 #ifndef ENABLE_MULTI_PRECISION
173 __int64 logic_dbl2int(calc_number_t *a);
174 double logic_int2dbl(calc_number_t *a);
175 #endif
176 void rpn_sin(calc_number_t *c);
177 void rpn_cos(calc_number_t *c);
178 void rpn_tan(calc_number_t *c);
179 void rpn_asin(calc_number_t *c);
180 void rpn_acos(calc_number_t *c);
181 void rpn_atan(calc_number_t *c);
182 void rpn_sinh(calc_number_t *c);
183 void rpn_cosh(calc_number_t *c);
184 void rpn_tanh(calc_number_t *c);
185 void rpn_asinh(calc_number_t *c);
186 void rpn_acosh(calc_number_t *c);
187 void rpn_atanh(calc_number_t *c);
188 BOOL rpn_validate_result(calc_number_t *c);
189 void rpn_int(calc_number_t *c);
190 void rpn_frac(calc_number_t *c);
191 void rpn_reci(calc_number_t *c);
192 void rpn_fact(calc_number_t *c);
193 void rpn_not(calc_number_t *c);
194 void rpn_pi(calc_number_t *c);
195 void rpn_2pi(calc_number_t *c);
196 void rpn_sign(calc_number_t *c);
197 void rpn_exp2(calc_number_t *c);
198 void rpn_exp3(calc_number_t *c);
199 void rpn_sqrt(calc_number_t *c);
200 void rpn_cbrt(calc_number_t *c);
201 void rpn_exp(calc_number_t *c);
202 void rpn_exp10(calc_number_t *c);
203 void rpn_ln(calc_number_t *c);
204 void rpn_log(calc_number_t *c);
205 void rpn_ave(calc_number_t *c);
206 void rpn_ave2(calc_number_t *c);
207 void rpn_sum(calc_number_t *c);
208 void rpn_sum2(calc_number_t *c);
209 void rpn_s(calc_number_t *c);
210 void rpn_s_m1(calc_number_t *c);
211 void rpn_dms2dec(calc_number_t *c);
212 void rpn_dec2dms(calc_number_t *c);
213 void rpn_zero(calc_number_t *c);
214 void rpn_copy(calc_number_t *dst, calc_number_t *src);
215 int rpn_is_zero(calc_number_t *c);
216 void rpn_alloc(calc_number_t *c);
217 void rpn_free(calc_number_t *c);
218
219 //
220
221 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base);
222 void convert_text2number_2(calc_number_t *a);
223 void convert_real_integer(unsigned int base);
224
225 //
226
227 INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
228
229 void ConvExecute(HWND hWnd);
230 void ConvAdjust(HWND hWnd, int n_cat);
231 void ConvInit(HWND hWnd);
232
233 #endif /* _CALC_H */