Вверх ↑
Ответов: 4621
Рейтинг: 746
#1: 2021-05-20 17:50:43 ЛС | профиль | цитата
У кого были проблемы с отображением результатов вычислений (преобразование чисел в строку) - протестируйте это.

1) Откройте файл HiAsm\compiler\FPC2\src\packages\KOL\kol.pas нормальным "Блокнотом" (Notepad++, SciTE, AkelPad и т.п.)
2) Замените функцию Extended2Str() со строки 20235 (до строки 20332) на эту:

function Extended2Str(E: Extended): KOLString;
const
DS: Char = '.';
PP = 3;
//15+8 = Extended
//15+7 = Double
Precision = {$ifdef FPC64}22{$else}23{$endif};
DefPE = 18; //= 19 in 64bit for Precision=23

var
Exponent, Q{, PP}, PE, DstL: Integer;
S: string;
Dst: PChar;

begin
Str(E:Precision, S); // '-2.00000000000000E+0001'

//PP := Pos('.', S);
if {PP = 0} S[PP] <> '.' then { NAN or other special case }
begin
Result := Trim(S); { Delete spaces }
// Result := '0';
Exit;
end;


{ Consider removing exponent }
//PE := Pos('E', Result);
//if PE = 0 then Exit; // Something wrong?
PE := DefPE;

{ Read exponent }
Exponent := 0;
Dst := @S[PE + 2]; // E+'0001' ; E+'001' in 64bit prec=23
while Dst^ <> #0 do
begin
Exponent := Exponent*10 + Ord(Dst^)-Ord('0');
Inc(Dst);
end;
if S[PE+1] = '-' then
Exponent := -Exponent;

{ Trim trailing zeros}
Dst := @S[PE - 1];
while (Dst^ = '0') do // Stop at non-zero or '.'
begin
Dec(PE);
Dec(Dst);
end;

if (PE = PP + 1) and (S[2] = '0') then // ' 0.00000000000000E+0000'
begin
Result := '0';
Exit;
end;


if Exponent >= 0 then
begin
{ Shift point to right }

DstL := Exponent + 1; // Digits before dst '.'

if S[1] = '-' then Inc(DstL); // '-' symbol

Q := PE - PP - 1; // Digits between src '.' and 'E'
if Q > Exponent then
begin
Inc(DstL); // Need '.' symbol in output
Inc(DstL, Q - Exponent); // Digits after dst '.'
end;

{ Compose output string }
SetLength(Result, DstL);
Dst := Pointer(Result);

// '-' symbol
if S[1] = '-' then
begin
Dst^ := '-';
Inc(Dst);
end;

Dst^ := S[2]; Inc(Dst); // 1 digit before src '.'

// Digits from S[3] to dst '.'
Q := PP + 1; // After src '.'
while (Q < PE) and (Exponent > 0) do
begin
Dst^ := S[Q];
Inc(Dst);
Inc(Q);
Dec(Exponent);
end;

if Q < PE then
begin
Dst^ := DS; // Dst '.'
Inc(Dst);
// Digits after dst '.'
while Q < PE do
begin
Dst^ := S[Q];
Inc(Dst);
Inc(Q);
end;
end
else // Extra '0'-s at the dst end
begin
while Exponent > 0 do
begin
Dst^ := '0';
Inc(Dst);
Dec(Exponent);
end;
end;

end
else
begin
{Shift point to left}
DstL := PE - PP - 1; // Digits between src '.' and 'E'
if S[1] = '-' then Inc(DstL); // '-' symbol
Inc(DstL); // '0' before '.'
Inc(DstL); // '.' symbol in output

Exponent := -Exponent; // Abs(Exponent)
Inc(DstL, Exponent); // Extra zeros at left

{ Compose output string }
SetLength(Result, DstL);
Dst := Pointer(Result);

// '-' symbol
if S[1] = '-' then
begin
Dst^ := '-';
Inc(Dst);
end;

Dst^ := '0'; Inc(Dst); // First '0'
Dst^ := DS; Inc(Dst); // '.'

for Q := 2 to Exponent do // Remained extra zeros at left
begin
Dst^ := '0';
Inc(Dst);
end;

Dst^ := S[2]; Inc(Dst); // 1 digit before src '.'
// Digits between src '.' and 'E'
for Q := PP + 1 to PE - 1 do
begin
Dst^ := S[Q];
Inc(Dst);
end;
end;

end;
3) Сохранитесь.
4) Выполните файлы
HiAsm\compiler\FPC2\src\_make_KOL_A.bat
HiAsm\compiler\FPC2\src\_make_KOL_U.bat



lisnic писал(а):
Компонент "принтер" не работает
Посмотрю.
карма: 26

0