diff --git a/TestSuite/Abs_Sqr_byte.pas b/TestSuite/Abs_Sqr_byte.pas index da0145850..715d0b297 100644 --- a/TestSuite/Abs_Sqr_byte.pas +++ b/TestSuite/Abs_Sqr_byte.pas @@ -5,4 +5,16 @@ var w: word := 65535; Assert(Sqr(w)=w*w); Assert(Abs(w)=w); + var sm: smallint := smallint.MaxValue; + Assert(Sqr(sm) = sm*sm); + var sh: shortint := shortint.MaxValue; + Assert(Sqr(sh) = sh*sh); + var lw: longword := longword.MaxValue; + Assert(Sqr(lw) = uint64(lw)*uint64(lw)); + var i: integer := integer.MaxValue; + Assert(Sqr(i) = int64(i)*int64(i)); + var i64: int64 := integer.MaxValue; + Assert(Sqr(i64) = i64*i64); + var ui64: uint64 := integer.MaxValue; + Assert(Sqr(ui64) = ui64*ui64); end. \ No newline at end of file diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index 009cc26e3..29428fb81 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -8212,7 +8212,7 @@ function LogN(base, x: real) := Math.Log(x) / Math.Log(base); function Sqrt(x: real) := Math.Sqrt(x); -function Sqr(x: integer): int64 := x * x; +function Sqr(x: integer): int64 := int64(x) * int64(x); function Sqr(x: shortint): integer := x * x; @@ -8222,11 +8222,11 @@ function Sqr(x: BigInteger): BigInteger := x * x; function Sqr(x: byte): integer := x * x; -function Sqr(x: word): uint64 := x * x; +function Sqr(x: word): uint64 := uint64(x) * uint64(x); -function Sqr(x: longword): uint64 := x * x; +function Sqr(x: longword): uint64 := uint64(x) * uint64(x); -function Sqr(x: int64): int64 := x * x; +function Sqr(x: int64): int64 := int64(x) * int64(x); function Sqr(x: uint64): uint64 := x * x;