2 * ReactOS Calc (Utility functions for IEEE-754 engine)
4 * Copyright 2007-2017, Carlo Bramini
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 void prepare_rpn_result_2(calc_number_t
*rpn
, TCHAR
*buffer
, int size
, int base
)
30 StringCchPrintf(buffer
, size
, _T("%I64X"), rpn
->i
);
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.
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;
42 if (calc
.sci_out
== TRUE
|| width
> MAX_LD_WIDTH
|| width
< -MAX_LD_WIDTH
)
43 StringCchPrintf(buffer
, size
, _T("%#.*e"), MAX_LD_WIDTH
-1, rpn
->f
);
47 StringCchPrintfEx(buffer
, size
, &ptr
, NULL
, 0, _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('.'));
54 /* put the string terminator for removing the final '0' (if any) */
56 /* check if the number finishes with '.' */
58 /* remove the dot (it will be re-added later) */
64 StringCchPrintf(buffer
, size
, _T("%I64o"), rpn
->i
);
75 memmove(buffer
+1, buffer
, (size
-1)*sizeof(TCHAR
));
86 void convert_text2number_2(calc_number_t
*a
)
92 _stscanf(calc
.buffer
, _T("%I64X"), &(a
->i
));
95 _stscanf(calc
.buffer
, _T("%lf"), &(a
->f
));
98 _stscanf(calc
.buffer
, _T("%I64o"), &(a
->i
));
103 while (*ptr
!= _T('\0')) {
105 if (*ptr
++ == _T('1'))
112 void convert_real_integer(unsigned int base
)
116 calc
.code
.f
= (double)calc
.code
.i
;
121 if (calc
.base
== IDC_RADIO_DEC
) {
122 calc
.code
.i
= (__int64
)calc
.code
.f
;
123 apply_int_mask(&calc
.code
);