ReactOS  0.4.13-dev-100-gc8611ae
rpn_mpfr.c File Reference
#include "calc.h"
Include dependency graph for rpn_mpfr.c:

Go to the source code of this file.

Classes

struct  stack_node_t
 
struct  calc_operator_t
 

Typedefs

typedef void(* operator_call) (calc_number_t *, calc_number_t *, calc_number_t *)
 
typedef void exec_call_t __GMP_PROTO((mpz_ptr, mpz_srcptr, mpz_srcptr))
 

Functions

static void rpn_add_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_sub_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_mul_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_div_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_pow_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_sqr_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_and_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_or_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_xor_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_shl_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_shr_f (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_add_i (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_sub_i (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_mul_i (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_div_i (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_mod_i (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_add_p (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_sub_p (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_mul_p (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void rpn_div_p (calc_number_t *r, calc_number_t *a, calc_number_t *b)
 
static void node_copy (calc_node_t *dst, calc_node_t *src)
 
static calc_node_tpop (void)
 
static int is_stack_empty (void)
 
static void push (calc_node_t *op)
 
static void rpn_exec_int (calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
 
void run_operator (calc_node_t *result, calc_node_t *a, calc_node_t *b, unsigned int operation)
 
static void evalStack (calc_number_t *number)
 
int exec_infix2postfix (calc_number_t *number, unsigned int func)
 
void exec_change_infix (void)
 
void exec_closeparent (calc_number_t *number)
 
int eval_parent_count (void)
 
void flush_postfix (void)
 
void start_rpn_engine (void)
 
void stop_rpn_engine (void)
 

Variables

static stack_node_tstack
 
static calc_node_t temp
 
static BOOL percent_mode
 
static const calc_operator_t operator_list []
 

Typedef Documentation

◆ __GMP_PROTO

typedef void exec_call_t __GMP_PROTO((mpz_ptr, mpz_srcptr, mpz_srcptr))

Definition at line 135 of file rpn_mpfr.c.

◆ operator_call

typedef void(* operator_call) (calc_number_t *, calc_number_t *, calc_number_t *)

Definition at line 28 of file rpn_mpfr.c.

Function Documentation

◆ eval_parent_count()

int eval_parent_count ( void  )

Definition at line 433 of file rpn_mpfr.c.

434 {
435  stack_node_t *s = stack;
436  int n = 0;
437 
438  while (s != NULL) {
439  if (s->node.operation == RPN_OPERATOR_PARENT)
440  n++;
441  s = (stack_node_t *)(s->next);
442  }
443  return n;
444 }
GLdouble n
Definition: glext.h:7729
smooth NULL
Definition: ftsmooth.c:416
GLdouble s
Definition: gl.h:2039
static stack_node_t * stack
Definition: rpn_mpfr.c:37

Referenced by update_parent_display().

◆ evalStack()

static void evalStack ( calc_number_t number)
static

Definition at line 328 of file rpn_mpfr.c.

329 {
330  calc_node_t *op, ip;
331  unsigned int prec;
332 
333  mpfr_init(ip.number.mf);
334  op = pop();
335  node_copy(&ip, op);
336  prec = operator_list[ip.operation].prec;
337  while (!is_stack_empty()) {
338  op = pop();
339 
340  if (prec <= operator_list[op->operation].prec) {
341  if (op->operation == RPN_OPERATOR_PARENT) continue;
342 
343  rpn_copy(&calc.prev, &ip.number);
344  run_operator(&ip, op, &ip, op->operation);
345  if (calc.is_nan) {
346  flush_postfix();
347  mpfr_clear(ip.number.mf);
348  return;
349  }
350  } else {
351  push(op);
352  break;
353  }
354  }
355 
356  if (ip.operation != RPN_OPERATOR_EQUAL && ip.operation != RPN_OPERATOR_PERCENT)
357  push(&ip);
358 
359  calc.prev_operator = op->operation;
360 
361  rpn_copy(number, &ip.number);
362  mpfr_clear(ip.number.mf);
363 }
static const calc_operator_t operator_list[]
Definition: rpn_mpfr.c:66
void rpn_copy(calc_number_t *dst, calc_number_t *src)
Definition: fun_ieee.c:591
static void node_copy(calc_node_t *dst, calc_node_t *src)
Definition: rpn_mpfr.c:84
BOOL is_nan
Definition: calc.h:183
void flush_postfix(void)
Definition: rpn_mpfr.c:446
static size_t double number
Definition: printf.c:64
int ip[4]
Definition: rtl.c:1176
unsigned int prec
Definition: rpn_ieee.c:31
unsigned int prev_operator
Definition: calc.h:198
Definition: dhcpd.h:61
void run_operator(calc_node_t *result, calc_node_t *a, calc_node_t *b, unsigned int operation)
Definition: rpn_mpfr.c:310
static void push(calc_node_t *op)
Definition: rpn_mpfr.c:114
UINT op
Definition: effect.c:223
static int is_stack_empty(void)
Definition: rpn_mpfr.c:109
calc_t calc
Definition: winmain.c:247
calc_number_t prev
Definition: calc.h:179
static calc_node_t * pop(void)
Definition: rpn_mpfr.c:90

Referenced by exec_infix2postfix().

◆ exec_change_infix()

void exec_change_infix ( void  )

Definition at line 397 of file rpn_mpfr.c.

398 {
399  stack_node_t *op = stack;
400 
401  if (op == NULL)
402  return;
403  if (op->node.operation == RPN_OPERATOR_PARENT ||
404  op->node.operation == RPN_OPERATOR_PERCENT ||
405  op->node.operation == RPN_OPERATOR_EQUAL)
406  return;
407  /* remove the head, it will be re-inserted with new operator */
408  pop();
409 }
smooth NULL
Definition: ftsmooth.c:416
UINT op
Definition: effect.c:223
static stack_node_t * stack
Definition: rpn_mpfr.c:37
static calc_node_t * pop(void)
Definition: rpn_mpfr.c:90

Referenced by DlgMainProc().

◆ exec_closeparent()

void exec_closeparent ( calc_number_t number)

Definition at line 411 of file rpn_mpfr.c.

412 {
413  calc_node_t *op, ip;
414 
415  rpn_alloc(&ip.number);
416  rpn_copy(&ip.number, number);
417  while (!is_stack_empty()) {
418  op = pop();
419 
420  if (op->operation == RPN_OPERATOR_PARENT)
421  break;
422 
423  run_operator(&ip, op, &ip, op->operation);
424  if (calc.is_nan) {
425  flush_postfix();
426  return;
427  }
428  }
429  rpn_copy(number, &ip.number);
430  rpn_free(&ip.number);
431 }
void rpn_copy(calc_number_t *dst, calc_number_t *src)
Definition: fun_ieee.c:591
void rpn_free(calc_number_t *c)
Definition: fun_ieee.c:605
BOOL is_nan
Definition: calc.h:183
void flush_postfix(void)
Definition: rpn_mpfr.c:446
static size_t double number
Definition: printf.c:64
int ip[4]
Definition: rtl.c:1176
Definition: dhcpd.h:61
void run_operator(calc_node_t *result, calc_node_t *a, calc_node_t *b, unsigned int operation)
Definition: rpn_mpfr.c:310
UINT op
Definition: effect.c:223
static int is_stack_empty(void)
Definition: rpn_mpfr.c:109
calc_t calc
Definition: winmain.c:247
static calc_node_t * pop(void)
Definition: rpn_mpfr.c:90
void rpn_alloc(calc_number_t *c)
Definition: fun_ieee.c:601

Referenced by run_rpar().

◆ exec_infix2postfix()

int exec_infix2postfix ( calc_number_t number,
unsigned int  func 
)

Definition at line 365 of file rpn_mpfr.c.

366 {
367  calc_node_t tmp;
368 
369  if (is_stack_empty() && func == RPN_OPERATOR_EQUAL) {
370  /* if a number has been entered with exponential */
371  /* notation, I may update it with normal mode */
372  if (calc.sci_in)
373  return 1;
374  return 0;
375  }
376 
377  if (func == RPN_OPERATOR_PERCENT)
378  percent_mode = TRUE;
379 
380  mpfr_init(tmp.number.mf);
381  rpn_copy(&tmp.number, number);
382  tmp.operation = func;
383 
384  push(&tmp);
385  mpfr_clear(tmp.number.mf);
386 
387  if (func == RPN_OPERATOR_NONE)
388  return 0;
389 
390  if (func != RPN_OPERATOR_PARENT) {
392  evalStack(number);
393  }
394  return 1;
395 }
GLenum func
Definition: glext.h:6028
#define TRUE
Definition: types.h:120
void rpn_copy(calc_number_t *dst, calc_number_t *src)
Definition: fun_ieee.c:591
static size_t double number
Definition: printf.c:64
static void evalStack(calc_number_t *number)
Definition: rpn_mpfr.c:328
static BOOL percent_mode
Definition: rpn_mpfr.c:39
BOOL sci_in
Definition: calc.h:185
unsigned int last_operator
Definition: calc.h:197
calc_number_t number
Definition: calc.h:133
static void push(calc_node_t *op)
Definition: rpn_mpfr.c:114
unsigned int operation
Definition: calc.h:134
static int is_stack_empty(void)
Definition: rpn_mpfr.c:109
calc_t calc
Definition: winmain.c:247

Referenced by DlgMainProc(), and run_lpar().

◆ flush_postfix()

void flush_postfix ( void  )

Definition at line 446 of file rpn_mpfr.c.

447 {
448  while (!is_stack_empty())
449  pop();
450  /* clear prev and last typed operators */
452  calc.last_operator = 0;
453 }
unsigned int prev_operator
Definition: calc.h:198
unsigned int last_operator
Definition: calc.h:197
static int is_stack_empty(void)
Definition: rpn_mpfr.c:109
calc_t calc
Definition: winmain.c:247
static calc_node_t * pop(void)
Definition: rpn_mpfr.c:90

Referenced by evalStack(), exec_closeparent(), and run_canc().

◆ is_stack_empty()

static int is_stack_empty ( void  )
static

Definition at line 109 of file rpn_mpfr.c.

110 {
111  return (stack == NULL);
112 }
smooth NULL
Definition: ftsmooth.c:416
Definition: _stack.h:47

Referenced by evalStack(), exec_closeparent(), exec_infix2postfix(), and flush_postfix().

◆ node_copy()

static void node_copy ( calc_node_t dst,
calc_node_t src 
)
static

Definition at line 84 of file rpn_mpfr.c.

85 {
86  mpfr_set(dst->number.mf, src->number.mf, MPFR_DEFAULT_RND);
87  dst->operation = src->operation;
88 }
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340

Referenced by evalStack(), and pop().

◆ pop()

static calc_node_t* pop ( void  )
static

Definition at line 90 of file rpn_mpfr.c.

91 {
92  void *next;
93 
94  if (stack == NULL)
95  return NULL;
96 
97  /* copy the node */
98  node_copy(&temp, &stack->node);
99  next = stack->next;
100 
101  /* free the node */
102  mpfr_clear(stack->node.number.mf);
103  free(stack);
104  stack = next;
105 
106  return &temp;
107 }
static calc_node_t temp
Definition: rpn_mpfr.c:38
static void node_copy(calc_node_t *dst, calc_node_t *src)
Definition: rpn_mpfr.c:84
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
Definition: _stack.h:47
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by evalStack(), exec_change_infix(), exec_closeparent(), and flush_postfix().

◆ push()

static void push ( calc_node_t op)
static

Definition at line 114 of file rpn_mpfr.c.

115 {
117 
118  mpfr_init_set(z->node.number.mf, op->number.mf, MPFR_DEFAULT_RND);
119  z->node.operation = op->operation;
120  z->next = stack;
121  stack = z;
122 }
GLdouble GLdouble z
Definition: glext.h:5874
Definition: _stack.h:47
#define malloc
Definition: debug_ros.c:4
UINT op
Definition: effect.c:223
static stack_node_t * stack
Definition: rpn_mpfr.c:37

Referenced by evalStack(), and exec_infix2postfix().

◆ rpn_add_f()

static void rpn_add_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 153 of file rpn_mpfr.c.

154 {
155  mpfr_add(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
156 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_add_i()

static void rpn_add_i ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 238 of file rpn_mpfr.c.

239 {
240  rpn_exec_int(r, a, b, mpz_add);
241 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_add_p()

static void rpn_add_p ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 270 of file rpn_mpfr.c.

271 {
272  mpfr_t tmp;
273 
274  mpfr_init(tmp);
275  mpfr_set(tmp, b->mf, MPFR_DEFAULT_RND);
276  mpfr_div_ui(tmp, tmp, 100, MPFR_DEFAULT_RND);
277  mpfr_add_ui(tmp, tmp, 1, MPFR_DEFAULT_RND);
278  mpfr_mul(r->mf, a->mf, tmp, MPFR_DEFAULT_RND);
279  mpfr_clear(tmp);
280 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_and_f()

static void rpn_and_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 176 of file rpn_mpfr.c.

177 {
178  rpn_exec_int(r, a, b, mpz_and);
179 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_div_f()

static void rpn_div_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 168 of file rpn_mpfr.c.

169 {
170  if (mpfr_sgn(b->mf) == 0)
171  calc.is_nan = TRUE;
172  else
173  mpfr_div(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
174 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_div_i()

static void rpn_div_i ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 253 of file rpn_mpfr.c.

254 {
255  if (mpfr_sgn(b->mf) == 0)
256  calc.is_nan = TRUE;
257  else
258  rpn_exec_int(r, a, b, mpz_tdiv_q);
259 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_div_p()

static void rpn_div_p ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 300 of file rpn_mpfr.c.

301 {
302  if (mpfr_sgn(b->mf) == 0)
303  calc.is_nan = TRUE;
304  else {
305  mpfr_mul_ui(r->mf, a->mf, 100, MPFR_DEFAULT_RND);
306  mpfr_div(r->mf, r->mf, b->mf, MPFR_DEFAULT_RND);
307  }
308 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_exec_int()

static void rpn_exec_int ( calc_number_t r,
calc_number_t a,
calc_number_t b,
exec_call_t  cb 
)
static

Definition at line 137 of file rpn_mpfr.c.

138 {
139  mpz_t ai, bi;
140 
141  mpz_init(ai);
142  mpz_init(bi);
143  mpfr_get_z(ai, a->mf, MPFR_DEFAULT_RND);
144  mpfr_get_z(bi, b->mf, MPFR_DEFAULT_RND);
145  cb(ai, ai, bi);
146  mpfr_set_z(r->mf, ai, MPFR_DEFAULT_RND);
147  mpz_clear(ai);
148  mpz_clear(bi);
149 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static DWORD cb
Definition: integrity.c:41
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by rpn_add_i(), rpn_and_f(), rpn_div_i(), rpn_mod_i(), rpn_mul_i(), rpn_or_f(), rpn_sub_i(), and rpn_xor_f().

◆ rpn_mod_i()

static void rpn_mod_i ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 261 of file rpn_mpfr.c.

262 {
263  if (mpfr_sgn(b->mf) == 0)
264  calc.is_nan = TRUE;
265  else
266  rpn_exec_int(r, a, b, mpz_tdiv_r);
267 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_mul_f()

static void rpn_mul_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 163 of file rpn_mpfr.c.

164 {
165  mpfr_mul(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
166 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_mul_i()

static void rpn_mul_i ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 248 of file rpn_mpfr.c.

249 {
250  rpn_exec_int(r, a, b, mpz_mul);
251 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_mul_p()

static void rpn_mul_p ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 294 of file rpn_mpfr.c.

295 {
296  mpfr_mul(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
297  mpfr_div_ui(r->mf, r->mf, 100, MPFR_DEFAULT_RND);
298 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_or_f()

static void rpn_or_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 181 of file rpn_mpfr.c.

182 {
183  rpn_exec_int(r, a, b, mpz_ior);
184 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_pow_f()

static void rpn_pow_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 217 of file rpn_mpfr.c.

218 {
219  mpfr_pow(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
220 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_shl_f()

static void rpn_shl_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 191 of file rpn_mpfr.c.

192 {
193  unsigned long e;
194 
195  mpfr_trunc(r->mf, b->mf);
196  if (mpfr_fits_ulong_p(r->mf, MPFR_DEFAULT_RND) == 0)
197  calc.is_nan = TRUE;
198  else {
199  e = mpfr_get_ui(r->mf, MPFR_DEFAULT_RND);
200  mpfr_mul_2exp(r->mf, a->mf, e, MPFR_DEFAULT_RND);
201  }
202 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
#define e
Definition: ke_i.h:82
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_shr_f()

static void rpn_shr_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 204 of file rpn_mpfr.c.

205 {
206  unsigned long e;
207 
208  mpfr_trunc(r->mf, b->mf);
209  if (mpfr_fits_ulong_p(r->mf, MPFR_DEFAULT_RND) == 0)
210  calc.is_nan = TRUE;
211  else {
212  e = mpfr_get_ui(r->mf, MPFR_DEFAULT_RND);
213  mpfr_div_2exp(r->mf, a->mf, e, MPFR_DEFAULT_RND);
214  }
215 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
#define e
Definition: ke_i.h:82
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_sqr_f()

static void rpn_sqr_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 222 of file rpn_mpfr.c.

223 {
224  if (mpfr_sgn(b->mf) == 0)
225  calc.is_nan = TRUE;
226  else {
227  mpfr_t tmp;
228 
229  mpfr_init(tmp);
230  mpfr_set(tmp, b->mf, MPFR_DEFAULT_RND);
231  mpfr_ui_div(tmp, 1, tmp, MPFR_DEFAULT_RND);
232  mpfr_pow(r->mf, a->mf, tmp, MPFR_DEFAULT_RND);
233  mpfr_clear(tmp);
234  }
235 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
BOOL is_nan
Definition: calc.h:183
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247

◆ rpn_sub_f()

static void rpn_sub_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 158 of file rpn_mpfr.c.

159 {
160  mpfr_sub(r->mf, a->mf, b->mf, MPFR_DEFAULT_RND);
161 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_sub_i()

static void rpn_sub_i ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 243 of file rpn_mpfr.c.

244 {
245  rpn_exec_int(r, a, b, mpz_sub);
246 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_sub_p()

static void rpn_sub_p ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 282 of file rpn_mpfr.c.

283 {
284  mpfr_t tmp;
285 
286  mpfr_init(tmp);
287  mpfr_set(tmp, b->mf, MPFR_DEFAULT_RND);
288  mpfr_div_ui(tmp, tmp, 100, MPFR_DEFAULT_RND);
289  mpfr_sub_ui(tmp, tmp, 1, MPFR_DEFAULT_RND);
290  mpfr_mul(r->mf, a->mf, tmp, MPFR_DEFAULT_RND);
291  mpfr_clear(tmp);
292 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ rpn_xor_f()

static void rpn_xor_f ( calc_number_t r,
calc_number_t a,
calc_number_t b 
)
static

Definition at line 186 of file rpn_mpfr.c.

187 {
188  rpn_exec_int(r, a, b, mpz_xor);
189 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static void rpn_exec_int(calc_number_t *r, calc_number_t *a, calc_number_t *b, exec_call_t cb)
Definition: rpn_mpfr.c:137
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

◆ run_operator()

void run_operator ( calc_node_t result,
calc_node_t a,
calc_node_t b,
unsigned int  operation 
)

Definition at line 310 of file rpn_mpfr.c.

314 {
315  if (calc.base == IDC_RADIO_DEC) {
316  if (percent_mode) {
318  operator_list[operation].op_p(&result->number, &a->number, &b->number);
319  } else
320  operator_list[operation].op_f(&result->number, &a->number, &b->number);
321  } else {
322  operator_list[operation].op_i(&result->number, &a->number, &b->number);
323  /* apply final limiter to result */
324  apply_int_mask(&result->number);
325  }
326 }
static const calc_operator_t operator_list[]
Definition: rpn_mpfr.c:66
DWORD base
Definition: calc.h:189
#define IDC_RADIO_DEC
Definition: resource.h:22
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
static BOOL percent_mode
Definition: rpn_mpfr.c:39
operator_call op_f
Definition: rpn_ieee.c:32
operator_call op_i
Definition: rpn_ieee.c:33
operator_call op_p
Definition: rpn_ieee.c:34
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
calc_t calc
Definition: winmain.c:247
GLuint64EXT * result
Definition: glext.h:11304
void apply_int_mask(calc_number_t *a)
Definition: fun_ieee.c:26

Referenced by evalStack(), exec_closeparent(), run_mm(), and run_mp().

◆ start_rpn_engine()

void start_rpn_engine ( void  )

Definition at line 455 of file rpn_mpfr.c.

456 {
457  mpf_set_default_prec(512);
458  mpfr_set_default_prec(512);
459  stack = NULL;
460  mpfr_init(calc.code.mf);
461  mpfr_init(calc.prev.mf);
462  mpfr_init(calc.memory.number.mf);
463  mpfr_init(temp.number.mf);
465 }
static calc_node_t temp
Definition: rpn_mpfr.c:38
calc_number_t code
Definition: calc.h:178
void rpn_zero(calc_number_t *c)
Definition: fun_ieee.c:586
smooth NULL
Definition: ftsmooth.c:416
Definition: _stack.h:47
calc_number_t number
Definition: calc.h:133
calc_node_t memory
Definition: calc.h:180
calc_t calc
Definition: winmain.c:247
calc_number_t prev
Definition: calc.h:179

Referenced by _tWinMain().

◆ stop_rpn_engine()

void stop_rpn_engine ( void  )

Definition at line 467 of file rpn_mpfr.c.

468 {
469  mpfr_clear(calc.code.mf);
470  mpfr_clear(calc.prev.mf);
471  mpfr_clear(calc.memory.number.mf);
472  mpfr_clear(temp.number.mf);
473 }
static calc_node_t temp
Definition: rpn_mpfr.c:38
calc_number_t code
Definition: calc.h:178
calc_number_t number
Definition: calc.h:133
calc_node_t memory
Definition: calc.h:180
calc_t calc
Definition: winmain.c:247
calc_number_t prev
Definition: calc.h:179

Referenced by _tWinMain().

Variable Documentation

◆ operator_list

const calc_operator_t operator_list[]
static
Initial value:
= {
{ 0, NULL, NULL, NULL, },
{ 0, NULL, NULL, NULL, },
{ 0, NULL, NULL, NULL, },
{ 1, rpn_or_f, rpn_or_f, NULL, },
{ 2, rpn_xor_f, rpn_xor_f, NULL, },
{ 3, rpn_and_f, rpn_and_f, NULL, },
{ 4, rpn_shl_f, rpn_shl_f, NULL, },
{ 4, rpn_shr_f, rpn_shr_f, NULL, },
{ 6, rpn_mod_i, rpn_mod_i, NULL, },
{ 7, rpn_pow_f, NULL, NULL, },
{ 7, rpn_sqr_f, NULL, NULL, },
}
static void rpn_pow_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:217
static void rpn_mul_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:163
static void rpn_shl_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:191
static void rpn_add_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:153
static void rpn_mod_i(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:261
static void rpn_sqr_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:222
static void rpn_sub_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:158
static void rpn_add_i(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:238
smooth NULL
Definition: ftsmooth.c:416
static void rpn_add_p(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:270
static void rpn_or_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:181
static void rpn_div_i(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:253
static void rpn_mul_p(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:294
static void rpn_sub_i(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:243
static void rpn_sub_p(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:282
static void rpn_shr_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:204
static void rpn_xor_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:186
static void rpn_mul_i(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:248
static void rpn_div_p(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:300
static void rpn_and_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:176
static void rpn_div_f(calc_number_t *r, calc_number_t *a, calc_number_t *b)
Definition: rpn_mpfr.c:168

Definition at line 66 of file rpn_mpfr.c.

Referenced by evalStack(), and run_operator().

◆ percent_mode

BOOL percent_mode
static

Definition at line 39 of file rpn_mpfr.c.

Referenced by exec_infix2postfix(), and run_operator().

◆ stack

Definition at line 37 of file rpn_mpfr.c.

Referenced by eval_parent_count(), exec_change_infix(), and push().

◆ temp

calc_node_t temp
static

Definition at line 38 of file rpn_mpfr.c.

Referenced by pop(), start_rpn_engine(), and stop_rpn_engine().