@@ -54,19 +54,17 @@ protected ComplexFormatter(PythonCore core, FormattingBuffer result, Spec spec)
54
54
Spec imSpec ;
55
55
if (hasNoSpecType ()) {
56
56
// no type spec: should be like the default __str__
57
- reSpec = getComponentSpecForNoSpecType (InternalFormat .Spec .NONE );
58
- imSpec = getComponentSpecForNoSpecType ('+' );
57
+ reSpec = getComponentSpecForNoSpecType (spec , InternalFormat .Spec .NONE );
58
+ imSpec = getComponentSpecForNoSpecType (spec , '+' );
59
59
} else {
60
60
// Turn off any flags that should apply to the result as a whole and not to the
61
- // individual
62
- // components (re/im). Sign of re is determined by the sign flag, sign of im will be
63
- // always
64
- // printed ('+' flag)
61
+ // individual components (re/im). Sign of re is determined by the sign flag, sign of im
62
+ // will be always printed ('+' flag)
65
63
reSpec = getComponentSpec (spec , spec .sign );
66
64
imSpec = getComponentSpec (spec , '+' );
67
65
}
68
- reFormatter = new FloatFormatter (core , result , reSpec );
69
- imFormatter = new FloatFormatter (core , result , imSpec );
66
+ reFormatter = new FloatFormatter (core , result , reSpec , false );
67
+ imFormatter = new FloatFormatter (core , result , imSpec , false );
70
68
}
71
69
72
70
public ComplexFormatter (PythonCore core , Spec spec ) {
@@ -85,10 +83,17 @@ private static Spec getComponentSpec(Spec spec, char sign) {
85
83
spec .type );
86
84
}
87
85
88
- private static Spec getComponentSpecForNoSpecType (char sign ) {
86
+ private static Spec getComponentSpecForNoSpecType (Spec spec , char sign ) {
89
87
// CPython uses "r" type, but also some internal flags that cause that integer values
90
88
// are printed without the decimal part, which is mostly what "g" does
91
- return new InternalFormat .Spec (' ' , '>' , sign , false , InternalFormat .Spec .UNSPECIFIED , Spec .NONE , -1 , 'g' );
89
+ int precision = spec .precision ;
90
+ char type = 'r' ;
91
+ if (precision < 0 ) {
92
+ precision = 0 ;
93
+ } else {
94
+ type = 'g' ;
95
+ }
96
+ return new InternalFormat .Spec (' ' , '>' , sign , false , InternalFormat .Spec .UNSPECIFIED , Spec .NONE , precision , type );
92
97
}
93
98
94
99
private boolean hasNoSpecType () {
0 commit comments