@@ -240,7 +240,7 @@ struct Decimal(size_t maxSize64)
240240 size_t  coefficientLength;
241241 static  if  (size_t .sizeof ==  8 )
242242 {
243-  if  (__ctfe  &&   size_t .sizeof  ==   8 )
243+  if  (__ctfe)
244244 {
245245 uint [coefficient.data.length *  2 ] data;
246246 foreach  (i; 0  ..  coefficient.length)
@@ -280,9 +280,25 @@ struct Decimal(size_t maxSize64)
280280 {
281281 //  try print decimal form without exponent
282282 //  up to 6 digits exluding leading 0. or final .0
283+  sizediff_t  s = this .exponent +  coefficientLength;
284+  if  (s <=  0 )
285+  {
286+  // 0.001....
287+  // 0.0001
288+  // 0.00001
289+  // 0.000001
290+  if  (s >=  - 2  ||  this .exponent >=  - 6 )
291+  {
292+  w.put(zeros[! coefficient.sign ..  - s +  2  +  1 ]);
293+  w.put(buffer[$ -  coefficientLength ..  $]);
294+  return ;
295+  }
296+  }
297+  else 
283298 if  (this .exponent >=  0 )
284299 {
285-  if  (this .exponent +  coefficientLength <=  6 )
300+  // /dddddd.0
301+  if  (s <=  6 )
286302 {
287303 buffer[$ -  coefficientLength -  1 ] = ' -' 
288304 w.put(buffer[$ -  coefficientLength -  coefficient.sign ..  $]);
@@ -291,25 +307,15 @@ struct Decimal(size_t maxSize64)
291307 }
292308 }
293309 else 
294-  if  (this .exponent <  0 )
295310 {
296-  if  (this .exponent >=  - 6  &&  coefficientLength <=  6 )
311+  // /dddddd.d....
312+  if  (s <=  6  ||  coefficientLength <=  6 )
297313 {
298-  sizediff_t  zerosLength = - this .exponent -  coefficientLength;
299-  if  (zerosLength >=  0 )
300-  {
301-  w.put(zeros[! coefficient.sign ..  zerosLength +  2  +  1 ]);
302-  w.put(buffer[$ -  coefficientLength ..  $]);
303-  return ;
304-  }
305-  else 
306-  {
307-  buffer[$ -  coefficientLength -  1 ] = ' -' 
308-  w.put(buffer[$ -  coefficientLength -  coefficient.sign ..  $ -  coefficientLength -  zerosLength]);
309-  buffer[$ -  coefficientLength -  zerosLength -  1 ] = ' .' 
310-  w.put(buffer[$ -  coefficientLength -  zerosLength -  1  ..  $]);
311-  return ;
312-  }
314+  buffer[$ -  coefficientLength -  1 ] = ' -' 
315+  w.put(buffer[$ -  coefficientLength -  coefficient.sign ..  $ -  coefficientLength +  s]);
316+  buffer[$ -  coefficientLength +  s -  1 ] = ' .' 
317+  w.put(buffer[$ -  coefficientLength +  s -  1  ..  $]);
318+  return ;
313319 }
314320 }
315321 }
@@ -340,7 +346,8 @@ struct Decimal(size_t maxSize64)
340346 else 
341347 enum  N = 11 ;
342348
343-  auto  expLength = printSignedToTail(exponent, buffer[$ -  N ..  $], ' \0 ' 
349+  //  prints e+/-exponent
350+  auto  expLength = printSignedToTail(exponent, buffer[$ -  N ..  $], ' +' 
344351 buffer[$ -  ++ expLength] = ' e' 
345352 w.put(buffer[$ -  expLength ..  $]);
346353 }
0 commit comments