1212
1313#if MICROPY_ENABLE_FLOAT
1414
15+ #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
16+ #include "formatfloat.h"
17+ #endif
18+
1519typedef struct _mp_obj_complex_t {
1620 mp_obj_base_t base ;
1721 mp_float_t real ;
@@ -22,11 +26,24 @@ mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
2226
2327STATIC void complex_print (void (* print )(void * env , const char * fmt , ...), void * env , mp_obj_t o_in , mp_print_kind_t kind ) {
2428 mp_obj_complex_t * o = o_in ;
29+ #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
30+ char buf [32 ];
31+ if (o -> real == 0 ) {
32+ format_float (o -> imag , buf , sizeof (buf ), 'g' , 6 , '\0' );
33+ print (env , "%s" , buf );
34+ } else {
35+ format_float (o -> real , buf , sizeof (buf ), 'g' , 6 , '\0' );
36+ print (env , "(%s+" , buf );
37+ format_float (o -> real , buf , sizeof (buf ), 'g' , 6 , '\0' );
38+ print (env , "%sj)" , buf );
39+ }
40+ #else
2541 if (o -> real == 0 ) {
2642 print (env , "%.8gj" , (double ) o -> imag );
2743 } else {
2844 print (env , "(%.8g+%.8gj)" , (double ) o -> real , (double ) o -> imag );
2945 }
46+ #endif
3047}
3148
3249STATIC mp_obj_t complex_make_new (mp_obj_t type_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
0 commit comments