xref: /reactos/base/applications/calc/calc.h (revision 845faec4)
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 
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 MAX_CALC_SIZE       256
45 
46 /*#define USE_KEYBOARD_HOOK*/
47 
48 #define SIZEOF(_ar)     (sizeof(_ar)/sizeof(_ar[1]))
49 
50 // RPN.C
51 
52 enum {
53     RPN_OPERATOR_PARENT,
54     RPN_OPERATOR_PERCENT,
55     RPN_OPERATOR_EQUAL,
56 
57     RPN_OPERATOR_OR,
58     RPN_OPERATOR_XOR,
59     RPN_OPERATOR_AND,
60     RPN_OPERATOR_LSH,
61     RPN_OPERATOR_RSH,
62     RPN_OPERATOR_ADD,
63     RPN_OPERATOR_SUB,
64     RPN_OPERATOR_MULT,
65     RPN_OPERATOR_DIV,
66     RPN_OPERATOR_MOD,
67     RPN_OPERATOR_POW,
68     RPN_OPERATOR_SQR,
69 
70     RPN_OPERATOR_NONE
71 };
72 
73 typedef union {
74 #ifdef ENABLE_MULTI_PRECISION
75     mpfr_t  mf;
76 #else
77     double  f;
78     INT64   i;
79     UINT64  u;
80 #endif
81 } calc_number_t;
82 
83 typedef struct {
84     calc_number_t number;
85     unsigned int  operation;
86     DWORD         base;
87 } calc_node_t;
88 
89 void run_operator(calc_node_t *result, calc_node_t *a,
90                   calc_node_t *b, unsigned int operation);
91 int  exec_infix2postfix(calc_number_t *, unsigned int);
92 void exec_closeparent(calc_number_t *);
93 int  eval_parent_count(void);
94 void flush_postfix(void);
95 void exec_change_infix(void);
96 void start_rpn_engine(void);
97 void stop_rpn_engine(void);
98 
99 typedef struct {
100     char *data;
101     char *ptr;
102     UINT  wm_msg;
103 } sequence_t;
104 
105 typedef struct {
106     calc_number_t    num;
107     DWORD            base;
108     void            *next;
109 } statistic_t;
110 
111 enum {
112     CALC_LAYOUT_SCIENTIFIC=0,
113     CALC_LAYOUT_STANDARD,
114     CALC_LAYOUT_CONVERSION,
115 };
116 
117 typedef struct {
118     HINSTANCE     hInstance;
119 #ifdef USE_KEYBOARD_HOOK
120     HHOOK         hKeyboardHook;
121 #endif
122     HWND          hWnd;
123     DWORD         layout;
124     TCHAR         buffer[MAX_CALC_SIZE];
125     TCHAR         source[MAX_CALC_SIZE];
126     TCHAR        *ptr;
127     calc_number_t code;
128     calc_number_t prev;
129     calc_node_t   memory;
130     statistic_t  *stat;
131     BOOL          is_memory;
132     BOOL          is_nan;
133     BOOL          sci_out;
134     BOOL          sci_in;
135     BOOL          usesep;
136     BOOL          is_menu_on;
137     signed int    esp;
138     DWORD         base;
139     DWORD         size;
140     DWORD         degr;
141     DWORD         action;
142     HWND          hStatWnd;
143     HWND          hConvWnd;
144     sequence_t    Clipboard;
145     sequence_t    Convert[2];
146     unsigned int  last_operator;
147     unsigned int  prev_operator;
148     TCHAR         sDecimal[8];
149     TCHAR         sThousand[8];
150     unsigned int  sDecimal_len;
151     unsigned int  sThousand_len;
152     signed int    x_coord;
153     signed int    y_coord;
154 } calc_t;
155 
156 extern calc_t calc;
157 
158 #define CALC_E      2.7182818284590452354
159 
160 #define CALC_PI_2   1.57079632679489661923
161 #define CALC_PI     3.14159265358979323846
162 #define CALC_3_PI_2 4.71238898038468985769
163 #define CALC_2_PI   6.283185307179586476925
164 
165 #define MODIFIER_INV    0x01
166 #define MODIFIER_HYP    0x02
167 #define NO_CHAIN        0x04
168 
169 void apply_int_mask(calc_number_t *a);
170 #ifdef ENABLE_MULTI_PRECISION
171 void validate_rad2angle(calc_number_t *c);
172 void validate_angle2rad(calc_number_t *c);
173 #else
174 __int64 logic_dbl2int(calc_number_t *a);
175 double logic_int2dbl(calc_number_t *a);
176 double validate_rad2angle(double a);
177 double validate_angle2rad(calc_number_t *c);
178 #endif
179 void rpn_sin(calc_number_t *c);
180 void rpn_cos(calc_number_t *c);
181 void rpn_tan(calc_number_t *c);
182 void rpn_asin(calc_number_t *c);
183 void rpn_acos(calc_number_t *c);
184 void rpn_atan(calc_number_t *c);
185 void rpn_sinh(calc_number_t *c);
186 void rpn_cosh(calc_number_t *c);
187 void rpn_tanh(calc_number_t *c);
188 void rpn_asinh(calc_number_t *c);
189 void rpn_acosh(calc_number_t *c);
190 void rpn_atanh(calc_number_t *c);
191 BOOL rpn_validate_result(calc_number_t *c);
192 void rpn_int(calc_number_t *c);
193 void rpn_frac(calc_number_t *c);
194 void rpn_reci(calc_number_t *c);
195 void rpn_fact(calc_number_t *c);
196 void rpn_not(calc_number_t *c);
197 void rpn_pi(calc_number_t *c);
198 void rpn_2pi(calc_number_t *c);
199 void rpn_sign(calc_number_t *c);
200 void rpn_exp2(calc_number_t *c);
201 void rpn_exp3(calc_number_t *c);
202 void rpn_sqrt(calc_number_t *c);
203 void rpn_cbrt(calc_number_t *c);
204 void rpn_exp(calc_number_t *c);
205 void rpn_exp10(calc_number_t *c);
206 void rpn_ln(calc_number_t *c);
207 void rpn_log(calc_number_t *c);
208 void rpn_ave(calc_number_t *c);
209 void rpn_sum(calc_number_t *c);
210 void rpn_s(calc_number_t *c);
211 void rpn_s_m1(calc_number_t *c);
212 void rpn_dms2dec(calc_number_t *c);
213 void rpn_dec2dms(calc_number_t *c);
214 void rpn_zero(calc_number_t *c);
215 void rpn_copy(calc_number_t *dst, calc_number_t *src);
216 int  rpn_is_zero(calc_number_t *c);
217 void rpn_alloc(calc_number_t *c);
218 void rpn_free(calc_number_t *c);
219 
220 void prepare_rpn_result_2(calc_number_t *rpn, TCHAR *buffer, int size, int base);
221 void convert_text2number_2(calc_number_t *a);
222 void convert_real_integer(unsigned int base);
223 
224 INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
225 
226 void ConvExecute(HWND hWnd);
227 void ConvAdjust(HWND hWnd, int n_cat);
228 void ConvInit(HWND hWnd);
229 
230 #endif /* _CALC_H */
231