3 void prepare_rpn_result_2(calc_number_t
*rpn
, TCHAR
*buffer
, int size
, int base
)
7 int width
, max_ld_width
;
8 unsigned long int n
, q
;
14 mpfr_get_z(zz
, rpn
->mf
, MPFR_DEFAULT_RND
);
15 mpfr_get_f(ff
, rpn
->mf
, MPFR_DEFAULT_RND
);
19 gmp_sprintf(temp
, "%ZX", zz
);
23 * The output display is much shorter in standard mode,
24 * so I'm forced to reduce the precision here :(
26 if (calc
.layout
== CALC_LAYOUT_STANDARD
)
31 /* calculate the width of integer number */
37 mpfr_abs(t
, rpn
->mf
, MPFR_DEFAULT_RND
);
38 mpfr_log10(t
, t
, MPFR_DEFAULT_RND
);
39 width
= 1 + mpfr_get_si(t
, MPFR_DEFAULT_RND
);
42 if (calc
.sci_out
== TRUE
|| width
> max_ld_width
|| width
< -max_ld_width
)
43 ptr
= temp
+ gmp_sprintf(temp
, "%*.*#Fe", 1, max_ld_width
, ff
);
45 ptr
= temp
+ gmp_sprintf(temp
, "%#*.*Ff", width
, ((max_ld_width
-width
-1)>=0) ? max_ld_width
-width
-1 : 0, ff
);
46 dst
= strchr(temp
, '.');
51 /* put the string terminator for removing the final '0' (if any) */
53 /* check if the number finishes with '.' */
55 /* remove the dot (it will be re-added later) */
60 gmp_sprintf(temp
, "%Zo", zz
);
63 /* if the number is zero, just write 0 ;) */
64 if (rpn_is_zero(rpn
)) {
69 /* repeat until a bit set to '1' is found */
79 /* now revert the string into TCHAR buffer */
81 buffer
[n
-q
-1] = (temp
[q
] == '1') ? TEXT('1') : TEXT('0');
82 buffer
[n
] = TEXT('\0');
90 _sntprintf(buffer
, SIZEOF(calc
.buffer
), TEXT("%s"), temp
);
93 void convert_text2number_2(calc_number_t
*a
)
102 case IDC_RADIO_HEX
: base
= 16; break;
103 case IDC_RADIO_DEC
: base
= 10; break;
104 case IDC_RADIO_OCT
: base
= 8; break;
105 case IDC_RADIO_BIN
: base
= 2; break;
110 * libmpfr and libgmp accept only ascii chars.
112 sz
= WideCharToMultiByte(CP_ACP
, 0, calc
.buffer
, -1, NULL
, 0, NULL
, NULL
);
115 temp
= (char *)_alloca(sz
);
116 sz
= WideCharToMultiByte(CP_ACP
, 0, calc
.buffer
, -1, temp
, sz
, NULL
, NULL
);
117 mpfr_strtofr(a
->mf
, temp
, NULL
, base
, MPFR_DEFAULT_RND
);
119 mpfr_strtofr(a
->mf
, calc
.buffer
, NULL
, base
, MPFR_DEFAULT_RND
);
123 void convert_real_integer(unsigned int base
)
131 if (calc
.base
== IDC_RADIO_DEC
) {
132 mpfr_trunc(calc
.code
.mf
, calc
.code
.mf
);
133 apply_int_mask(&calc
.code
);