ReactOS  0.4.13-dev-544-gede3fdd
utl_ieee.c File Reference
#include "calc.h"
Include dependency graph for utl_ieee.c:

Go to the source code of this file.

Macros

#define MAX_LD_WIDTH   16
 

Functions

void prepare_rpn_result_2 (calc_number_t *rpn, TCHAR *buffer, int size, int base)
 
void convert_text2number_2 (calc_number_t *a)
 
void convert_real_integer (unsigned int base)
 

Macro Definition Documentation

◆ MAX_LD_WIDTH

#define MAX_LD_WIDTH   16

Function Documentation

◆ convert_real_integer()

void convert_real_integer ( unsigned int  base)

Definition at line 112 of file utl_ieee.c.

113 {
114  switch (base) {
115  case IDC_RADIO_DEC:
116  calc.code.f = (double)calc.code.i;
117  break;
118  case IDC_RADIO_OCT:
119  case IDC_RADIO_BIN:
120  case IDC_RADIO_HEX:
121  if (calc.base == IDC_RADIO_DEC) {
122  calc.code.i = (__int64)calc.code.f;
124  }
125  break;
126  }
127 }
DWORD base
Definition: calc.h:189
calc_number_t code
Definition: calc.h:178
#define IDC_RADIO_DEC
Definition: resource.h:22
double f
Definition: calc.h:126
#define IDC_RADIO_BIN
Definition: resource.h:24
#define IDC_RADIO_HEX
Definition: resource.h:21
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
if(!(yy_init))
Definition: macro.lex.yy.c:714
INT64 i
Definition: calc.h:127
#define IDC_RADIO_OCT
Definition: resource.h:23
calc_t calc
Definition: winmain.c:247
#define __int64
Definition: basetyps.h:16
void apply_int_mask(calc_number_t *a)
Definition: fun_ieee.c:26

◆ convert_text2number_2()

void convert_text2number_2 ( calc_number_t a)

Definition at line 86 of file utl_ieee.c.

87 {
88  TCHAR *ptr;
89 
90  switch (calc.base) {
91  case IDC_RADIO_HEX:
92  _stscanf(calc.buffer, _T("%I64X"), &(a->i));
93  break;
94  case IDC_RADIO_DEC:
95  _stscanf(calc.buffer, _T("%lf"), &(a->f));
96  break;
97  case IDC_RADIO_OCT:
98  _stscanf(calc.buffer, _T("%I64o"), &(a->i));
99  break;
100  case IDC_RADIO_BIN:
101  ptr = calc.buffer;
102  a->i = 0;
103  while (*ptr != _T('\0')) {
104  a->i <<= 1;
105  if (*ptr++ == _T('1'))
106  a->i |= 1;
107  }
108  break;
109  }
110 }
DWORD base
Definition: calc.h:189
#define IDC_RADIO_DEC
Definition: resource.h:22
#define _stscanf
Definition: tchar.h:557
#define IDC_RADIO_BIN
Definition: resource.h:24
#define IDC_RADIO_HEX
Definition: resource.h:21
static PVOID ptr
Definition: dispmode.c:27
TCHAR buffer[MAX_CALC_SIZE]
Definition: calc.h:175
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define IDC_RADIO_OCT
Definition: resource.h:23
calc_t calc
Definition: winmain.c:247

◆ prepare_rpn_result_2()

void prepare_rpn_result_2 ( calc_number_t rpn,
TCHAR buffer,
int  size,
int  base 
)

Definition at line 23 of file utl_ieee.c.

24 {
25  calc_number_t tmp;
26  int width;
27 
28  switch (base) {
29  case IDC_RADIO_HEX:
30  _stprintf(buffer, _T("%I64X"), rpn->i);
31  break;
32  case IDC_RADIO_DEC:
33 /*
34  * Modified from 17 to 16 for fixing this bug:
35  * 14+14+6.3+6.3= 40.5999999 instead of 40.6
36  * So, it's probably better to leave the least
37  * significant digit out of the display.
38  */
39 #define MAX_LD_WIDTH 16
40  /* calculate the width of integer number */
41  width = (rpn->f==0) ? 1 : (int)log10(fabs(rpn->f))+1;
43  _stprintf(buffer, _T("%#.*e"), MAX_LD_WIDTH-1, rpn->f);
44  else {
45  TCHAR *ptr, *dst;
46 
47  ptr = buffer + _stprintf(buffer, _T("%#*.*f"), width, ((MAX_LD_WIDTH-width-1)>=0) ? MAX_LD_WIDTH-width-1 : 0, rpn->f);
48  /* format string ensures there is a '.': */
49  dst = _tcschr(buffer, _T('.'));
50  while (--ptr > dst)
51  if (*ptr != _T('0'))
52  break;
53 
54  /* put the string terminator for removing the final '0' (if any) */
55  ptr[1] = _T('\0');
56  /* check if the number finishes with '.' */
57  if (ptr == dst)
58  /* remove the dot (it will be re-added later) */
59  ptr[0] = _T('\0');
60  }
61 #undef MAX_LD_WIDTH
62  break;
63  case IDC_RADIO_OCT:
64  _stprintf(buffer, _T("%I64o"), rpn->i);
65  break;
66  case IDC_RADIO_BIN:
67  if (rpn->i == 0) {
68  buffer[0] = _T('0');
69  buffer[1] = _T('\0');
70  break;
71  }
72  tmp = *rpn;
73  buffer[0] = _T('\0');
74  while (tmp.u) {
75  memmove(buffer+1, buffer, (size-1)*sizeof(TCHAR));
76  if (tmp.u & 1)
77  buffer[0] = _T('1');
78  else
79  buffer[0] = _T('0');
80  tmp.u >>= 1;
81  }
82  break;
83  }
84 }
GLint GLint GLsizei width
Definition: gl.h:1546
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
UINT64 u
Definition: calc.h:128
#define TRUE
Definition: types.h:120
#define MAX_LD_WIDTH
BOOL sci_out
Definition: calc.h:184
#define IDC_RADIO_DEC
Definition: resource.h:22
double f
Definition: calc.h:126
GLuint buffer
Definition: glext.h:5915
#define IDC_RADIO_BIN
Definition: resource.h:24
#define IDC_RADIO_HEX
Definition: resource.h:21
static PVOID ptr
Definition: dispmode.c:27
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLsizeiptr size
Definition: glext.h:5919
INT64 i
Definition: calc.h:127
_STLP_DECLSPEC complex< float > _STLP_CALL log10(const complex< float > &)
Definition: complex.cpp:230
_Check_return_ _CRT_JIT_INTRINSIC double __cdecl fabs(_In_ double x)
#define _stprintf
Definition: utility.h:124
GLenum GLenum dst
Definition: glext.h:6340
#define IDC_RADIO_OCT
Definition: resource.h:23
calc_t calc
Definition: winmain.c:247