Error float_out( p_otokens tokens, floatnum x, int scale, signed char base, char outmode) { t_number_desc n; _emptytokens(tokens); /* do some sanity checks first */ if (!_validmode(outmode) || scale < 0 || !_isvalidbase(base)) return InvalidParam; _clearnumber(&n); if (float_iszero(x)) n.prefix.base = IO_BASE_ZERO; else if (!float_isnan(x)) n.prefix.base = base; if (!_isvalidbase(n.prefix.base)) /* NaN and 0 are handled here */ return desc2str(tokens, &n, 0); n.prefix.sign = float_getsign(x); float_abs(x); switch (outmode) { case IO_MODE_FIXPOINT: return _outfixp(tokens, x, &n, scale); case IO_MODE_ENG: return _outeng(tokens, x, &n, scale); case IO_MODE_COMPLEMENT: return _outcompl(tokens, x, &n, 0); default: return _outsci(tokens, x, &n, scale); } }
char *get_file_name(void) { TFileName FileName; if (!AknCommonDialogs::RunSelectDlgLD(FileName, 0)) return NULL; return desc2str(FileName); }
static Error _outscidec( p_otokens tokens, floatnum x, p_number_desc n, int scale) { float_checkedround(x, scale + 1); n->exp = float_getexponent(x); float_setexponent(x, 0); _setfndesc(n, x); return desc2str(tokens, n, scale); }
static Error _outfixpdec( p_otokens tokens, floatnum x, p_number_desc n, int scale) { int digits; digits = float_getexponent(x) + scale + 1; if (digits <= 0) /* underflow */ return IOConversionUnderflow; if (float_round(x, x, digits, TONEAREST) != TRUE) /* float_round() can err if the number contains too many digits */ return float_geterror(); _setfndesc(n, x); return desc2str(tokens, n, scale); }
static Error _outscihex( p_otokens tokens, floatnum x, p_number_desc n, int scale) { t_longint l; Error result; n->exp = _extractexp(x, scale, n->prefix.base); result = _fixp2longint(n, &l, x, scale); if (result != Success) return result; /* rounding in _fixp2longint may have increased the exponent */ n->exp += n->fracpart.seq.digits - 1 - scale; _setscale(n, &l, n->fracpart.seq.digits - 1); return desc2str(tokens, n, scale); }
static Error _outfixphex( p_otokens tokens, floatnum x, p_number_desc n, int scale) { t_longint l; Error result; float_copy(x, x, DECPRECISION+1); result = _fixp2longint(n, &l, x, scale); if (result != Success) return result; if (l.length == 0) return IOConversionUnderflow; _setscale(n, &l, scale); return desc2str(tokens, n, scale); }
static Error _outengdec( p_otokens tokens, floatnum x, p_number_desc n, int scale) { int shift; float_checkedround(x, scale + 1); n->exp = float_getexponent(x); if (n->exp < 0) shift = 2 - (-n->exp-1) % 3; else shift = n->exp % 3; float_setexponent(x, shift); n->exp -= shift; _setfndesc(n, x); return desc2str(tokens, n, scale - shift); }