mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-21 22:41:49 +02:00
* fixed evaluation of "mod" operator for tconstexprint with signed operands
(part of mantis #15453) git-svn-id: trunk@14516 -
This commit is contained in:
parent
81f34dd4bb
commit
04606982ac
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10166,6 +10166,7 @@ tests/webtbs/tw15377.pp svneol=native#text/pascal
|
||||
tests/webtbs/tw1539.pp svneol=native#text/plain
|
||||
tests/webtbs/tw15391.pp svneol=native#text/plain
|
||||
tests/webtbs/tw15415.pp svneol=native#text/plain
|
||||
tests/webtbs/tw15453a.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1567.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1573.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1592.pp svneol=native#text/plain
|
||||
|
@ -380,7 +380,8 @@ end;
|
||||
|
||||
operator mod (const a,b:Tconstexprint):Tconstexprint;
|
||||
|
||||
var aa,bb:qword;
|
||||
var aa,bb,r:qword;
|
||||
sa,sb:boolean;
|
||||
|
||||
begin
|
||||
if a.overflow or b.overflow then
|
||||
@ -389,20 +390,32 @@ begin
|
||||
exit;
|
||||
end;
|
||||
result.overflow:=false;
|
||||
if a.signed then
|
||||
aa:=qword(a.svalue)
|
||||
sa:=a.signed and (a.svalue<0);
|
||||
if sa then
|
||||
{$Q-}
|
||||
aa:=qword(-a.svalue)
|
||||
{$ifdef ena_q}{$Q+}{$endif}
|
||||
else
|
||||
aa:=a.uvalue;
|
||||
if b.signed then
|
||||
bb:=qword(b.svalue)
|
||||
sb:=b.signed and (b.svalue<0);
|
||||
if sb then
|
||||
{$Q-}
|
||||
bb:=qword(-b.svalue)
|
||||
{$ifdef ena_q}{$Q+}{$endif}
|
||||
else
|
||||
bb:=b.uvalue;
|
||||
if bb=0 then
|
||||
result.overflow:=true
|
||||
else
|
||||
begin
|
||||
result.signed:=false;
|
||||
result.uvalue:=aa mod bb;
|
||||
{ the sign of a modulo operation only depends on the sign of the
|
||||
dividend }
|
||||
r:=aa mod bb;
|
||||
result.signed:=sa;
|
||||
if not sa then
|
||||
result.uvalue:=r
|
||||
else
|
||||
result.svalue:=-int64(r);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
12
tests/webtbs/tw15453a.pp
Normal file
12
tests/webtbs/tw15453a.pp
Normal file
@ -0,0 +1,12 @@
|
||||
uses Math;
|
||||
|
||||
var
|
||||
Result, Remainder: SmallInt;
|
||||
begin
|
||||
Result := -9 div 5;
|
||||
Remainder := -9 mod 5;
|
||||
writeln(result,' - ',remainder);
|
||||
if (result<>-1) or
|
||||
(remainder<>-4) then
|
||||
halt(1);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user