@@ -151,12 +151,12 @@ function Ceiling (const ANumber: Double): Integer; inline;
151151 Result := Trunc(ANumber) + Ord(Frac(ANumber) > 0 );
152152end ;
153153
154- function RoundExDouble (const aTemp: Double): Double ; inline;
154+ function RoundExInteger (const aTemp: Double): Integer ; inline;
155155var
156156 vTmp: Double;
157157begin
158158 vTmp := aTemp * 10 ;
159- Result := Ceiling (vTmp) / 10 ;
159+ Result := Ceiling (vTmp);
160160end ;
161161
162162// ---------------------------------------------------
@@ -473,8 +473,24 @@ procedure TOneBRC.MergeAll;
473473
474474// ---------------------------------------------------
475475
476+ function MyFormatInt (const aIn: SmallInt): AnsiString; inline;
477+ begin
478+ Result := IntToStr(aIn);
479+ Insert (' .' , Result, Length(Result));
480+
481+ if Result[1 ] = ' .' then begin
482+ Insert (' 0' , Result, 1 );
483+ exit;
484+ end ;
485+
486+ if (Result[1 ] = ' -' ) and (Result[2 ] = ' .' ) then
487+ Insert(' 0' , Result, 2 );
488+ end ;
489+
490+ // ---------------------------------------------------
491+
476492procedure TOneBRC.GenerateOutput ;
477- var vMin, vMean, vMax: Double ;
493+ var vMean: Integer ;
478494 vStream: TStringStream;
479495 I, N: Int64;
480496 vData: PStationData;
@@ -507,14 +523,12 @@ procedure TOneBRC.GenerateOutput;
507523 // debatable, and the whole output generation is < 0.3 seconds, so not exactly worth it
508524 vHash := crc32c(0 , @vStations[i][1 ], Length (vStations[i]));
509525 FStationsDicts[0 ].TryGetValue(vHash, vData);
510- vMin := vData^.Min/10 ;
511- vMax := vData^.Max/10 ;
512- vMean := RoundExDouble(vData^.Sum/vData^.Count/10 );
526+ vMean := RoundExInteger(vData^.Sum/vData^.Count/10 );
513527
514528 vStream.WriteString(
515- vStations[i] + ' =' + FormatFloat( ' 0.0 ' , vMin )
516- + ' /' + FormatFloat( ' 0.0 ' , vMean)
517- + ' /' + FormatFloat( ' 0.0 ' , vMax ) + ' , '
529+ vStations[i] + ' =' + MyFormatInt(vData^.Min )
530+ + ' /' + MyFormatInt( vMean)
531+ + ' /' + MyFormatInt(vData^.Max ) + ' , '
518532 );
519533 Inc(I);
520534 end ;
@@ -645,4 +659,3 @@ procedure TOneBRCApp.WriteHelp;
645659end .
646660
647661{ $ENDREGION}
648-
0 commit comments