# Integer\*integer == integer^2 is not always true

**URL:** <https://scilab.discourse.group/t/integer-integer-integer-2-is-not-always-true/1209>\
**Category:** General usage\
**Created:** [July 26, 2026, 6:30pm UTC](https://scilab.discourse.group/t/integer-integer-integer-2-is-not-always-true/1209 "2026-07-26T18:30:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xenomanes](https://avatars.discourse-cdn.com/v4/letter/x/c37758/32.png) [@Xenomanes](https://scilab.discourse.group/u/Xenomanes)\
**Post date:** [July 26, 2026, 6:30pm UTC](https://scilab.discourse.group/t/integer-integer-integer-2-is-not-always-true/1209/1 "2026-07-26T18:30:07Z")

</div>

Dear scilab,

while running scilab-2026.0.1 on my elderly MX Linux box  
and experimenting with some large numbers using both double  
and int64 (available since 6.0) types,  
I had an experience that shook my confidence in arithmetic.  
I squared `'y=int64("708158977")' and got `“501489136705686528”.  
This (an even square of an odd prime) aroused some suspicion,  
so I tried `'y*y' and got `“501489136705686529”.  
Casting `'y' to uint64 did not change the results. `

`To check I applied (via javasci) methods `‘pow’ and `'multiply' of the java.math.BigInteger package to `‘y’.  
Both gave identical answers, namely the `y\*y’ value.

There must be an AI inside scilab, a set of Anomalous Int64s.  
I conjectured that the members of AI are large prime numbers.  
But this is not true. Only “large” is a necessary property.  
The phenomenon seems to set in at about 94999001, which is 79_307_3917.  
You can try yourself some numbers until “3037000001”, which is not far  
from the largest int64 that can be squared without overflow. Here  
the difference `y\*y-y^2’ is -383.

Cordialement Xenomanes

---

<div class="post-metadata">

**Author:** ![davidcl](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/davidcl/32/1029_2.png) [@davidcl](https://scilab.discourse.group/u/davidcl)\
**Post date:** [July 27, 2026, 7:38am UTC](https://scilab.discourse.group/t/integer-integer-integer-2-is-not-always-true/1209/2 "2026-07-27T07:38:37Z")

</div>

Hello,

I translated your examples into executable Scilab code:

```scilab
--> n = "708158977"; [int64(n)**2 ; int64(n)*int64(n)]

 ans = [2x1 int64]

  501489136705686528
  501489136705686529

```

There is an implicit cast to double for the power operation, which leads to this behavior. Could you report a bug on [Work items · scilab / scilab · GitLab](https://gitlab.com/scilab/scilab/-/issues) ?

Thanks

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/vmagnin/32/1048_2.png) [@vmagnin](https://scilab.discourse.group/u/vmagnin)\
**Post date:** [September 7, 2026, 9:24am UTC](https://scilab.discourse.group/t/integer-integer-integer-2-is-not-always-true/1209/3 "2026-09-07T09:24:06Z")

</div>

The result is OK for powers of 2, but is getting worse as we move away from powers of 2:

```auto
--> n = 2^31; [int64(n)^2 ; int64(n)*int64(n)]

 ans = [2x1 int64]

  4611686018427387904
  4611686018427387904

--> n = 2^31-1; [int64(n)^2 ; int64(n)*int64(n)]

 ans = [2x1 int64]

  4611686014132420608
  4611686014132420609

--> n = 2^31-20; [int64(n)^2 ; int64(n)*int64(n)]

 ans = [2x1 int64]

  4611685932528042496
  4611685932528042384

--> n = 2^31-200; [int64(n)^2 ; int64(n)*int64(n)]

 ans = [2x1 int64]

  4611685159433968640
  4611685159433968704

```
