- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
void dwflt_to_str(DWORD dw, char *pch, int &nsmb)
{
DWORD dw_a = dw;
char ch_a;
char tbldec[] = "0123456789";
nsmb = 0;
if (dw_a == 0) { pch[0] = '0'; nsmb++; goto lab2; }
while (dw_a != 0)
{
pch[nsmb] = tbldec[dw_a%10]; dw_a /= 10; nsmb++;
}
dw_a = nsmb/2;
while (dw_a)
{
ch_a = pch[nsmb - dw_a]; pch[nsmb - dw_a] = pch[dw_a - 1]; pch[dw_a - 1] = ch_a; dw_a--;
}
lab2:
pch[nsmb] = 0;
}
const int n_fr2 = 7; // - эта константа определяет фиксированное число цифр после точки в выводимой строке, представляющей float.
void float_to_str(float flt, char *pchar, int &nsmb)
{
int i, deg, ns_int, ns_frac;
double frac_dbl;
DWORD dw_f, mant, intg, fract;
DW_FL f_flt;
char szfl_int[16], szfl_frac[16];
f_flt.fl = flt;
dw_f = f_flt.dw;
if (dw_f == 0) { pchar[0] = '0'; pchar[1] = '.'; pchar[2] = '0'; pchar[3] = 0; nsmb = 3; return; }
if (dw_f & 0x80000000) { pchar[0] = '-'; } else { pchar[0] = '+'; }
deg = int((dw_f & 0x7F800000) >> 23) - 127;
mant = (dw_f & 0x007FFFFF) | 0x00800000;
if (deg == 0) { intg = 1; fract = dw_f & 0x007FFFFF; goto lab_1; }
if (deg > 0) { intg = mant >> (23 - deg); fract = ((dw_f & 0x007FFFFF) << deg) & 0x007FFFFF; goto lab_1; }
if (deg < 0) { intg = 0; fract = ((dw_f & 0x007FFFFF) | 0x00800000) >> (-deg); }
lab_1:
frac_dbl = double(fract)*1.1920928955078125;// 1.1920928955078125 = 10^n_fr2 / 2^23 = 10^7 / 2^23
fract = (int)frac_dbl;
dwflt_to_str(intg, szfl_int, ns_int);
nsmb = 1; i = ns_int; while (i) { pchar[i + 1] = szfl_int[i]; i--; } pchar[1] = szfl_int[0];
nsmb += ns_int; pchar[nsmb] = '.'; nsmb++;
dwflt_to_str(fract, szfl_frac, ns_frac); szfl_frac[n_fr2] = 0;
i = ns_frac; while (i) { szfl_frac[6 - ns_frac + i] = szfl_frac[i - 1]; i--; }
i = n_fr2 - ns_frac; while (i) { szfl_frac[i - 1] = '0'; i--; }
i = n_fr2 - 1; while (i) { pchar[nsmb + i] = szfl_frac[i]; i--; } pchar[nsmb] = szfl_frac[0];
nsmb += n_fr2; pchar[nsmb] = 0;
}
void float_to_str_exp(float flt, char *pchar, int &nsmb)
{
int i, deg, poli, ns_int, ns_frac, ns_poli;
double frac_dbl;
DWORD dw_f, mant, intg, fract;
DW_FL f_flt;
char szfl_int[16], szfl_frac[16];
f_flt.fl = flt;
dw_f = f_flt.dw;
if (dw_f == 0) { pchar[0] = '0'; pchar[1] = '.'; pchar[2] = '0'; pchar[3] = 0; nsmb = 3; return; }
if (dw_f & 0x80000000) { pchar[0] = '-'; } else { pchar[0] = '+'; }
deg = int((dw_f & 0x7F800000) >> 23) - 127;
mant = (dw_f & 0x007FFFFF) | 0x00800000;
if (deg == 0) { intg = 1; fract = dw_f & 0x007FFFFF; goto lab_1; }
if (deg > 0) { intg = mant >> (23 - deg); fract = ((dw_f & 0x007FFFFF) << deg) & 0x007FFFFF; goto lab_1; }
if (deg < 0) { intg = 0; fract = ((dw_f & 0x007FFFFF) | 0x00800000) >> (-deg); }
lab_1:
frac_dbl = double(fract)*1.1920928955078125;// 1.1920928955078125 = 10^n_fr2 / 2^23 = 10^7 / 2^23
fract = (int)frac_dbl;
dwflt_to_str(intg, szfl_int, ns_int);
dwflt_to_str(fract, szfl_frac, ns_frac); szfl_frac[n_fr2] = 0;
if (intg != 0)
{
nsmb = 1; i = ns_int; while (i) { pchar[i + 2] = szfl_int[i]; i--; } pchar[1] = szfl_int[0];
pchar[2] = '.'; nsmb += ns_int + 1; poli = ns_int - 1;
}
else
{
i = ns_frac - 1; while (i) { pchar[2 + i] = szfl_frac[i]; i--; } pchar[1] = szfl_frac[0];
pchar[2] = '.'; nsmb = 3;//nsmb += ns_frac + 1;
poli = ns_frac - n_fr2 - 1; goto lab_2;
}
i = ns_frac; while (i) { szfl_frac[6 - ns_frac + i] = szfl_frac[i - 1]; i--; }
i = n_fr2 - ns_frac; while (i) { szfl_frac[i - 1] = '0'; i--; }
i = n_fr2 - 1; while (i) { pchar[nsmb + i] = szfl_frac[i]; i--; } pchar[nsmb] = szfl_frac[0];
lab_2:
nsmb += n_fr2; pchar[nsmb] = 'E';
int_to_str(poli, &pchar[nsmb + 1], ns_poli);
nsmb += ns_poli + 1; pchar[nsmb] = 0;
}