mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-24 05:37:41 +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/tw1539.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15391.pp svneol=native#text/plain
|
tests/webtbs/tw15391.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw15415.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/tw1567.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1573.pp svneol=native#text/plain
|
tests/webtbs/tw1573.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1592.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;
|
operator mod (const a,b:Tconstexprint):Tconstexprint;
|
||||||
|
|
||||||
var aa,bb:qword;
|
var aa,bb,r:qword;
|
||||||
|
sa,sb:boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if a.overflow or b.overflow then
|
if a.overflow or b.overflow then
|
||||||
@ -389,20 +390,32 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
result.overflow:=false;
|
result.overflow:=false;
|
||||||
if a.signed then
|
sa:=a.signed and (a.svalue<0);
|
||||||
aa:=qword(a.svalue)
|
if sa then
|
||||||
|
{$Q-}
|
||||||
|
aa:=qword(-a.svalue)
|
||||||
|
{$ifdef ena_q}{$Q+}{$endif}
|
||||||
else
|
else
|
||||||
aa:=a.uvalue;
|
aa:=a.uvalue;
|
||||||
if b.signed then
|
sb:=b.signed and (b.svalue<0);
|
||||||
bb:=qword(b.svalue)
|
if sb then
|
||||||
|
{$Q-}
|
||||||
|
bb:=qword(-b.svalue)
|
||||||
|
{$ifdef ena_q}{$Q+}{$endif}
|
||||||
else
|
else
|
||||||
bb:=b.uvalue;
|
bb:=b.uvalue;
|
||||||
if bb=0 then
|
if bb=0 then
|
||||||
result.overflow:=true
|
result.overflow:=true
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
result.signed:=false;
|
{ the sign of a modulo operation only depends on the sign of the
|
||||||
result.uvalue:=aa mod bb;
|
dividend }
|
||||||
|
r:=aa mod bb;
|
||||||
|
result.signed:=sa;
|
||||||
|
if not sa then
|
||||||
|
result.uvalue:=r
|
||||||
|
else
|
||||||
|
result.svalue:=-int64(r);
|
||||||
end;
|
end;
|
||||||
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