- 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
float FilesObj::Read_float(unsigned char *sym_hangar_p,int pos_start,int pos_max,int *new_pos){ // read one float from loaded file
int pos,qui_flag,f_sign,aftr_dot;
unsigned char sym;
float res;
//
// > start
//
f_sign=1; // positive by default
res=0; // zero res by default
aftr_dot=-1; // before dot stage now
*new_pos=pos_start; // new position ret by default
//
// < start
// > decoding loop
//
for (pos=pos_start; pos<=pos_max; pos++){ // loop selected 8-bit area
sym=*(sym_hangar_p+pos); // 8-bit symbol for test
qui_flag=1; // time to finish decode float
//
if (sym>=48 && sym<=57){ // nums
qui_flag=0; // clear: time to finish decode float
if (aftr_dot<0){
res=(res*10)+((float)(sym-48)); // -before- dot stage
}else{aftr_dot*=10;
res+=( ((float)(sym-48))/((float)(aftr_dot)) ); // -after- dot stage
}}
//
if (sym==45){ // sym "-"
qui_flag=0; // clear: time to finish decode float
f_sign=-1; // flag: negative value
}
if (sym==46){ // sym "."
qui_flag=0; // clear: time to finish decode float
aftr_dot=1; // flag: after dot stage now
}
if (sym==32 && pos==pos_start){ // one space at start allowed. some programs set one additional space before number.
qui_flag=0; // clear: time to finish decode float
}
//
*new_pos=pos; // new position return: first non-value position
if (qui_flag!=0){break;} // decoding finished, quit and return res
}
//
// < decoding loop
// > result return
//
if (f_sign<0){res=-res;} // sign apply
return (res); // actual return
//
// < result return
//
}
- Говнокод !
- Если есть какие-то мысли, как его можно улучшить, скажи. Но улучшить его будет непросто, хотя бы потому что ты не знаешь моих привычек в форматировании. И невольно будешь предлагать свои привычки в оформлении, которые мне разумеется не нужны.
Это ж чем надо упороться? Дальше перестановки байт в слове дело ещё не доходило...
>Although the ubiquitous x86 processors of today use little-endian storage for all types of data (integer, floating point, BCD), there have been a few historical machines where floating point numbers were represented in big-endian form while integers were represented in little-endian form.[16] There are old ARM processors that have half little-endian, half big-endian floating point representation for double-precision numbers: both 32-bit words are stored in little-endian like integer registers, but the most significant one first. Because there have been many floating point formats with no "network" standard representation for them, there is no formal standard for transferring floating point values between diverse systems. It may therefore appear strange that the widespread IEEE 754 floating point standard does not specify endianness.
> but the most significant one first
Они там сумасшедшие что-ли все?
А ты еби байты по одному, если лень с этим заморачиваться :)
упрт