1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-20 12:32:58 +00:00
This commit is contained in:
mrdudz 2022-11-18 01:52:00 +01:00
parent e8e39db4ca
commit 7370478f80

View File

@ -9,38 +9,30 @@ char *_ftostr(char *buffer, float f) {
signed long n0; signed long n0;
int is_negative; int is_negative;
unsigned long raw_value = *((unsigned long*)(&f)); unsigned long raw_value = *((unsigned long*)(&f));
// f = -1.23f; is_negative = (raw_value & 0x80000000) ? 1 : 0; // very hacky indeed
intpart = (signed long)(f); intpart = (signed long)(f);
if (intpart < 0) {
intpart *= -1;
}
is_negative = (raw_value & 0x80000000) ? 1 : 0;
// printf("f:%f\n",f);
f2 = intpart; f2 = intpart;
// printf("f2:%f\n",f2);
// printf("f2:%08lx\n",*((unsigned long*)(&f2)));
if (f2 > f) { if (f2 > f) {
if (intpart > 0) { if (intpart > 0) {
--intpart; --intpart;
} }
} }
if (intpart < 0) {
intpart *= -1;
}
f2 = intpart; f2 = intpart;
fracpart = f - f2; fracpart = f - f2;
// printf("fracpart:%f\n",fracpart);
// printf("fracpart:%08lx\n",*((unsigned long*)(&fracpart)));
// f1 = fracpart * 10000.0f;
f1 = 10000.0f; f1 = 10000.0f;
// printf("fracpart:%08lx\n",*((unsigned long*)(&f1)));
// f1 *= fracpart;
f1 = f1 * fracpart; f1 = f1 * fracpart;
// f1 = fracpart;
// f1 = intpart;
// printf("fracpart:%f\n",f1);
// printf("fracpart:%08lx\n",*((unsigned long*)(&f1)));
n0 = (signed long)f1; n0 = (signed long)f1;
if (n0 < 0) { if (n0 < 0) {
n0 *= -1; n0 *= -1;