EtchedPixels / Fuzix-Compiler-Kit

Fuzix C Compiler Project
Other
49 stars 14 forks source link

support6800/__castf.c support6800/__castf.c does not convert correctly #140

Closed zu2 closed 4 weeks ago

zu2 commented 4 weeks ago

castf_u and castf_uc can be made shorter, but for simplicity they are made to match long.

--- ../Fuzix-Compiler-Kit/support6800/__castf.c 2024-10-13 22:57:57
+++ support6800/__castf.c   2024-10-27 17:27:01
@@ -2,23 +2,25 @@

 unsigned long _castf_ul(uint32_t a1)
 {
-    if (a1 & 0x7FFFFFFFUL)
-        return MANT(a1) >> (EXP(a1) - EXCESS - 24);
-    return 0;
+   int shift;
+    if ((a1 & 0x7FFFFFFFUL)==0)
+       return 0;
+   shift = 24-EXP(a1)+EXCESS;
+   if (shift>=24)
+       return 0;
+   if (shift<0)
+       return MANT(a1)<<-shift;
+   return MANT(a1) >> shift;
 }

 unsigned _castf_u(uint32_t a1)
 {
-    if (a1 & 0x7FFFFFFFUL)
-        return MANT(a1) >> (EXP(a1) - EXCESS - 24);
-    return 0;
+   return _castf_ul(a1);
 }

 unsigned char _castf_uc(uint32_t a1)
 {
-    if (a1 & 0x7FFFFFFFUL)
-        return MANT(a1) >> (EXP(a1) - EXCESS - 24);
-    return 0;
+   return _castf_ul(a1);
 }

 long _castf_l(uint32_t a1)
zu2 commented 4 weeks ago

now works Mandelbrot set. cf. https://kyo-ta04.github.io/memo/

スクリーンショット 2024-10-27 17 36 23

EtchedPixels commented 4 weeks ago

Thanks