[NTDLL]
[reactos.git] / reactos / base / applications / calc / calc.h
1 #pragma once
2
3 #include <windows.h>
4 #include <tchar.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <math.h>
8 #include <float.h>
9 #include <malloc.h>
10 #ifndef DISABLE_HTMLHELP_SUPPORT
11 #include <htmlhelp.h>
12 #endif
13 #include <limits.h>
14
15 /* Messages reserved for the main dialog */
16 #define WM_CLOSE_STATS (WM_APP+1)
17 #define WM_HANDLE_CLIPBOARD (WM_APP+2)
18 #define WM_INSERT_STAT (WM_APP+3)
19 #define WM_LOAD_STAT (WM_APP+4)
20 #define WM_START_CONV (WM_APP+5)
21 #define WM_HANDLE_FROM (WM_APP+6)
22 #define WM_HANDLE_TO (WM_APP+7)
23
24 #ifdef ENABLE_MULTI_PRECISION
25 #include <mpfr.h>
26
27 #ifndef MPFR_DEFAULT_RND
28 #define MPFR_DEFAULT_RND mpfr_get_default_rounding_mode ()
29 #endif
30
31 #define LOCAL_EXP_SIZE 100000000L
32 #else
33
34 #define LOCAL_EXP_SIZE 10000L
35
36 #endif
37
38 #include "resource.h"
39
40 #ifndef IDC_STATIC
41 #define IDC_STATIC ((DWORD)-1)
42 #endif
43
44 #define CALC_VERSION TEXT("1.11")
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 //
161 #define CALC_E 2.7182818284590452354
162
163 #define CALC_PI_2 1.57079632679489661923
164 #define CALC_PI 3.14159265358979323846
165 #define CALC_3_PI_2 4.71238898038468985769
166 #define CALC_2_PI 6.283185307179586476925
167
168 #define MODIFIER_INV 0x01
169 #define MODIFIER_HYP 0x02
170 #define NO_CHAIN 0x04
171
172 void apply_int_mask(calc_number_t *a);
173 #ifdef ENABLE_MULTI_PRECISION
174 void validate_rad2angle(calc_number_t *c);
175 void validate_angle2rad(calc_number_t *c);
176 #else
177 __int64 logic_dbl2int(calc_number_t *a);
178 double logic_int2dbl(calc_number_t *a);
179 double validate_rad2angle(double a);
180 double validate_angle2rad(calc_number_t *c);
181 #endif
182 void rpn_sin(calc_number_t *c);
183 void rpn_cos(calc_number_t *c);
184 void rpn_tan(calc_number_t *c);
185 void rpn_asin(calc_number_t *c);
186 void rpn_acos(calc_number_t *c);
187 void rpn_atan(calc_number_t *c);
188 void rpn_sinh(calc_number_t *c);
189 void rpn_cosh(calc_number_t *c);
190 void rpn_tanh(calc_number_t *c);
191 void rpn_asinh(calc_number_t *c);
192 void rpn_acosh(calc_number_t *c);
193 void rpn_atanh(calc_number_t *c);
194 BOOL rpn_validate_result(calc_number_t *c);
195 void rpn_int(calc_number_t *c);
196 void rpn_frac(calc_number_t *c);
197 void rpn_reci(calc_number_t *c);
198 void rpn_fact(calc_number_t *c);
199 void rpn_not(calc_number_t *c);
200 void rpn_pi(calc_number_t *c);
201 void rpn_2pi(calc_number_t *c);
202 void rpn_sign(calc_number_t *c);
203 void rpn_exp2(calc_number_t *c);
204 void rpn_exp3(calc_number_t *c);
205 void rpn_sqrt(calc_number_t *c);
206 void rpn_cbrt(calc_number_t *c);
207 void rpn_exp(calc_number_t *c);
208 void rpn_exp10(calc_number_t *c);
209 void rpn_ln(calc_number_t *c);
210 void rpn_log(calc_number_t *c);
211 void rpn_ave(calc_number_t *c);
212 void rpn_sum(calc_number_t *c);
213 void rpn_s(calc_number_t *c);
214 void rpn_s_m1(calc_number_t *c);
215 void rpn_dms2dec(calc_number_t *c);
216 void rpn_dec2dms(calc_number_t *c);
217 void rpn_zero(calc_number_t *c);
218 void rpn_copy(calc_number_t *dst, calc_number_t *src);
219 int rpn_is_zero(calc_number_t *c);
220 void rpn_alloc(calc_number_t *c);
221 void rpn_free(calc_number_t *c);
222
223 //
224
225 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base);
226 void convert_text2number_2(calc_number_t *a);
227 void convert_real_integer(unsigned int base);
228
229 //
230
231 INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
232
233 //
234
235 void ConvExecute(HWND hWnd);
236 void ConvAdjust(HWND hWnd, int n_cat);
237 void ConvInit(HWND hWnd);