Indeed, this seems to have been the exact problem. Thanks<br><br><div class="gmail_quote">On Fri, Jul 15, 2011 at 5:04 PM, Coleburn, Randy <span dir="ltr"><<a href="mailto:rcolebur@scires.com">rcolebur@scires.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">




<div>
<div style="font-family:Tahoma;direction:ltr;color:#000000;font-size:x-small">
<div>Ken:</div>
<div><font face="tahoma"></font> </div>
<div><font face="tahoma">More info re the fix checked in by Rodney Bates:</font></div>
<div><font face="tahoma"></font> </div>
<div>
<div>CVSROOT:        /usr/cvs<br>
Changes by:     rodney@birch.   11/07/15 21:17:09<br>
<br>
Modified files:<br>
        cm3/m3-libs/m3core/src/convert/: Tag: release_branch_cm3_5_8 <br>
                                         Convert.m3 <br>
<br>
Log message:<br>
        Fix a tiny typo in Convert.DigitsL that was causing<br>
        digit 6 to display as '4' and 4 to display as '0'.<br>
<br>
Regards,</div>
<div><font face="tahoma">Randy Coleburn</font></div>
</div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma"></font> </div>
<div style="direction:ltr">
<hr>
<font color="#000000" size="2" face="Tahoma"><b>From:</b> Coleburn, Randy<br>
<b>Sent:</b> Friday, July 15, 2011 5:54 PM<br>
<b>To:</b> Ken Durocher<div><div></div><div class="h5"><br>
<b>Cc:</b> m3devel<br>
<b>Subject:</b> Re: [M3devel] LONGINT problem?<br>
</div></div></font><br>
</div><div><div></div><div class="h5">
<div></div>
<div>
<div style="font-family:Tahoma;direction:ltr;color:#000000;font-size:x-small">
<div>Ken:</div>
<div><font face="tahoma">With all due respect, I don't think Daniel is on the right track.</font></div>
<div><font face="tahoma">I note that one of our developers checked in a fix that may solve your problem.</font></div>
<div><font face="tahoma">There seems to have been a problem in formatting the output where certain digits got messed up.</font></div>
<div><font face="tahoma">Try updating your system with this new fix and run your program again.  It may solve your problem.</font></div>
<div><font face="tahoma">Regards,</font></div>
<div><font face="tahoma">Randy Coleburn</font></div>
<div dir="ltr"><font color="#000000" size="2" face="Tahoma"></font> </div>
<div style="direction:ltr">
<hr>
<font color="#000000" size="2" face="Tahoma"><b>From:</b> Ken Durocher [<a href="mailto:kcdurocher@gmail.com" target="_blank">kcdurocher@gmail.com</a>]<br>
<b>Sent:</b> Friday, July 15, 2011 5:53 PM<br>
<b>To:</b> Daniel Alejandro Benavides D.<br>
<b>Cc:</b> m3devel; Coleburn, Randy<br>
<b>Subject:</b> Re: [M3devel] LONGINT problem?<br>
</font><br>
</div>
<div></div>
<div>I just checekd, and I can confirm that the LONGINT version of the code produces INCORRECT results on a 32 bit system, as well as a 64 bit system.  Both are running Linux, with cm3 5.8.6<br>
<br>
<div class="gmail_quote">On Thu, Jul 14, 2011 at 8:30 PM, Daniel Alejandro Benavides D.
<span dir="ltr"><<a href="mailto:dabenavidesd@yahoo.es" target="_blank">dabenavidesd@yahoo.es</a>></span> wrote:<br>
<blockquote style="border-left:#ccc 1px solid;margin:0px 0px 0px 0.8ex;padding-left:1ex" class="gmail_quote">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top">Hi all:<br>
the problem as I see is that your program isn't typed for any platform in specific just to give you the best answer, then I would stick to the original and track down the source of the problem (this is very point of type checking, and e.g extended static checking
 if I may say so, the need to verify your statements, the other approach is too cumbersome, i.e make it believe it works when it doesn't). IMHO this a symptom of UNSAFE type checking problem, rather of programming or programmer error.<br>

I hope to be clarified about this, as far as I know LONGINT isn't INTEGER but a bigger or equal type (a bigger INTEGER) which translates better to be a super type, since it isn't I wonder why is that needed a different type checker for that (we can transform
 INTEGER to be the true super type and LONGINT to be a subtype), can't we make the same checking and just range check everything else (so it doesn't bother to rewrite every platform code, a bad symptom certainly, yet I approve the change in the language SPEC
 but not its type checking).<br>
Thanks in advance<br>
<br>
--- El <b>jue, 14/7/11, Coleburn, Randy <i><<a href="mailto:rcolebur@SCIRES.COM" target="_blank">rcolebur@SCIRES.COM</a>></i></b> escribió:<br>
<blockquote style="border-left:rgb(16,16,255) 2px solid;padding-left:5px;margin-left:5px">
<br>
De: Coleburn, Randy <<a href="mailto:rcolebur@SCIRES.COM" target="_blank">rcolebur@SCIRES.COM</a>><br>
Asunto: Re: [M3devel] LONGINT problem?<br>
Para: "m3devel" <<a href="mailto:m3devel@elegosoft.com" target="_blank">m3devel@elegosoft.com</a>>, "Ken Durocher" <<a href="mailto:kcdurocher@gmail.com" target="_blank">kcdurocher@gmail.com</a>><br>

Fecha: jueves, 14 de julio, 2011 18:15
<div>
<div></div>
<div><br>
<br>
<div>
<div>
<p><span style="color:rgb(31,73,125);font-size:11pt">Ken:</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt"></span> </p>
<p><span style="color:rgb(31,73,125);font-size:11pt">On what platform (OS and CPU) are you building and running your Modula-3 program?</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt"></span> </p>
<p><span style="color:rgb(31,73,125);font-size:11pt">Support for LONGINT is a relatively new addition to CM3, so it is possible that something is broken.  Perhaps your program can help us track it down. 
</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt"></span> </p>
<p><span style="color:rgb(31,73,125);font-size:11pt">I haven’t checked thru your program yet, but the fact that it gives the right answer using INTEGER, but not when using LONGINT, seems to point to the LONGINT implementation as a potential problem source
 we should investigate.</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt"></span> </p>
<p><span style="color:rgb(31,73,125);font-size:11pt">Regards,</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt">Randy Coleburn</span></p>
<p><span style="color:rgb(31,73,125);font-size:11pt"></span> </p>
<div style="border-bottom:medium none;border-left:medium none;padding-bottom:0in;padding-left:0in;padding-right:0in;border-top:1pt solid;border-right:medium none;padding-top:3pt">
<p style="margin-left:0.5in"><b><span style="font-size:10pt">From:</span></b><span style="font-size:10pt"> Ken Durocher [mailto:<a href="mailto:kcdurocher@gmail.com" target="_blank">kcdurocher@gmail.com</a>]
<br>
<b>Sent:</b> Thursday, July 14, 2011 7:00 PM<br>
<b>To:</b> Jay K<br>
<b>Cc:</b> m3devel<br>
<b>Subject:</b> Re: [M3devel] LONGINT problem?</span></p>
</div>
<p style="margin-left:0.5in"> </p>
<div>
<p style="margin-left:0.5in">Sorry, to clarify, the LONGINT code does NOT give the correct output, but the INTEGER code DOES.</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<p style="margin-left:0.5in">I did not write this C code, but it's output is the same as all the other examples (there is a Java example too, if you want that):</p>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<div>
<p style="margin-left:0.5in">#include <stdio.h></p>
</div>
<div>
<p style="margin-left:0.5in">#include <stdlib.h></p>
</div>
<div>
<p style="margin-left:0.5in">#include <stdint.h></p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">/* should be 64-bit integers if going over 1 billion */</p>
</div>
<div>
<p style="margin-left:0.5in">typedef unsigned long xint;</p>
</div>
<div>
<p style="margin-left:0.5in">#define FMT "%lu"</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">xint total, prim, max_peri;</p>
</div>
<div>
<p style="margin-left:0.5in">xint U[][9] =  {{ 1, -2, 2,  2, -1, 2,  2, -2, 3},</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>{ 1,  2, 2,  2,  1, 2,  2,  2, 3},</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>{-1,  2, 2, -2,  1, 2, -2,  2, 3}};</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">void new_tri(xint in[])</p>
</div>
<div>
<p style="margin-left:0.5in">{</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>int i;</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>xint t[3], p = in[0] + in[1] + in[2];</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>if (p > max_peri) return;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>prim ++;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>/* for every primitive triangle, its multiples would be right-angled too;</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>* count them up to the max perimeter */</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>total += max_peri / p;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>/* recursively produce next tier by multiplying the matrices */</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>for (i = 0; i < 3; i++) {</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>t[0] = U[i][0] * in[0] + U[i][1] * in[1] + U[i][2] * in[2];</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>t[1] = U[i][3] * in[0] + U[i][4] * in[1] + U[i][5] * in[2];</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>t[2] = U[i][6] * in[0] + U[i][7] * in[1] + U[i][8] * in[2];</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>new_tri(t);</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>}</p>
</div>
<div>
<p style="margin-left:0.5in">}</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">int main()</p>
</div>
<div>
<p style="margin-left:0.5in">{</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>xint seed[3] = {3, 4, 5};</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>for (max_peri = 10; max_peri <= 100000000; max_peri *= 10) {</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>total = prim = 0;</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>new_tri(seed);</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in"><span>                        </span>printf(<span> 
</span>"Up to "FMT": "FMT" triples, "FMT" primitives.\n",</p>
</div>
<div>
<p style="margin-left:0.5in"><span>                                    </span>max_peri, total, prim);</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>}</p>
</div>
<div>
<p style="margin-left:0.5in"><span>            </span>return 0;</p>
</div>
<div>
<p style="margin-left:0.5in">}</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">The output from that code is:</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<div>
<p style="margin-left:0.5in">Up to 10: 0 triples, 0 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 100: 17 triples, 7 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 1000: 325 triples, 70 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 10000: 4858 triples, 703 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 100000: 64741 triples, 7026 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 1000000: 808950 triples, 70229 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 10000000: 9706567 triples, 702309 primitives.</p>
</div>
<div>
<p style="margin-left:0.5in">Up to 100000000: 113236940 triples, 7023027 primitives.</p>
</div>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">Note this output corresponds with the INTEGER output.</p>
</div>
<p style="margin-left:0.5in"> </p>
<div>
<p style="margin-left:0.5in">On Thu, Jul 14, 2011 at 5:17 PM, Jay K <<a href="http://mc/compose?to=jay.krell@cornell.edu" rel="nofollow" target="_blank">jay.krell@cornell.edu</a>> wrote:</p>
<div>
<div>
<p style="margin-bottom:12pt;margin-left:0.5in;margin-right:0in">Can you isolate if the problem is the formating/printing, or if it is in the computation?<br>
i.e.:<br>
<br>
Use "unsafe" and print out a little hex dump of the integer/longint variables?<br>
<br>
As well, what does LONGINT on a 64bit machine do? Eh..well, it might work, it might not.<br>
Doesn't really matter. Let's focus on non-working 32bit machine with LONGINT.<br>
<br>
Also, please confirm which is the right, i.e. by writing it in C.<br>
Also, maybe just try to format as unsigned/hex using the safe interfaces?<br>
Also, this will be good to add to our automated tests. Assuming it doesn't run too slowly.<br>
Assuming it reproduces for anyone else (sorry, a bit rude of me).<br>
<br>
Later, thank you,<br>
 - Jay<br>
<br>
</p>
<div>
<div style="text-align:center;margin-left:0.5in" align="center">
<hr align="center" size="2" width="100%">
</div>
<p style="margin-left:0.5in">Date: Thu, 14 Jul 2011 16:26:05 -0500<br>
From: <a href="http://mc/compose?to=kcdurocher@gmail.com" rel="nofollow" target="_blank">
kcdurocher@gmail.com</a><br>
To: <a href="http://mc/compose?to=m3devel@elegosoft.com" rel="nofollow" target="_blank">
m3devel@elegosoft.com</a><br>
Subject: [M3devel] LONGINT problem?</p>
<div>
<div>
<p style="margin-left:0.5in"><br>
<br>
I was writing a program to calculate "Pythagorean triples" recursively, and ran into a problem.  Here's the program:</p>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<div>
<p style="margin-left:0.5in">MODULE PyTriples EXPORTS Main;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">IMPORT IO, Fmt;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">VAR tcnt, pcnt, max, i: LONGINT;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">PROCEDURE NewTriangle(a, b, c: LONGINT; VAR tcount, pcount: LONGINT) =</p>
</div>
<div>
<p style="margin-left:0.5in">  VAR perim := a + b + c;      </p>
</div>
<div>
<p style="margin-left:0.5in">  BEGIN</p>
</div>
<div>
<p style="margin-left:0.5in">    IF perim <= max THEN</p>
</div>
<div>
<p style="margin-left:0.5in">      pcount := pcount + 1L;</p>
</div>
<div>
<p style="margin-left:0.5in">      tcount := tcount + max DIV perim;</p>
</div>
<div>
<p style="margin-left:0.5in">      NewTriangle(a-2L*b+2L*c, 2L*a-b+2L*c, 2L*a-2L*b+3L*c, tcount, pcount);</p>
</div>
<div>
<p style="margin-left:0.5in">      NewTriangle(a+2L*b+2L*c, 2L*a+b+2L*c, 2L*a+2L*b+3L*c, tcount, pcount);</p>
</div>
<div>
<p style="margin-left:0.5in">      NewTriangle(2L*b+2L*c-a, b+2L*c-2L*a, 2L*b+3L*c-2L*a, tcount, pcount);</p>
</div>
<div>
<p style="margin-left:0.5in">    END;</p>
</div>
<div>
<p style="margin-left:0.5in">  END NewTriangle;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">BEGIN</p>
</div>
<div>
<p style="margin-left:0.5in">i := 100L;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">REPEAT</p>
</div>
<div>
<p style="margin-left:0.5in">  max := i;</p>
</div>
<div>
<p style="margin-left:0.5in">  tcnt := 0L;</p>
</div>
<div>
<p style="margin-left:0.5in">  pcnt := 0L;</p>
</div>
<div>
<p style="margin-left:0.5in">  NewTriangle(3L, 4L, 5L, tcnt, pcnt);</p>
</div>
<div>
<p style="margin-left:0.5in">  IO.Put(Fmt.LongInt(i) & ": " & Fmt.LongInt(tcnt) & " Triples, " &</p>
</div>
<div>
<p style="margin-left:0.5in">    Fmt.LongInt(pcnt) & " Primitives\n");</p>
</div>
<div>
<p style="margin-left:0.5in">  i := i * 10L;</p>
</div>
<div>
<p style="margin-left:0.5in">UNTIL i = 10000000L;</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">END PyTriples.</p>
</div>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">This outputs:</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<div>
<p style="margin-left:0.5in">100: 17 Triples, 7 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">1000: 325 Triples, 70 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">10000: 0858 Triples, 703 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">100000: 40701 Triples, 7024 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">1000000: 808950 Triples, 70229 Primitives</p>
</div>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">However, if I just use INTEGER on a 64 bit machine, I get the proper output:</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<div>
<p style="margin-left:0.5in">100: 17 Triples, 7 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">1000: 325 Triples, 70 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">10000: 4858 Triples, 703 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">100000: 64741 Triples, 7026 Primitives</p>
</div>
<div>
<p style="margin-left:0.5in">1000000: 808950 Triples, 70229 Primitives</p>
</div>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
<div>
<p style="margin-left:0.5in">Note how 10000 and 100000 are different. The code is literally exactly the same, only with LONGINT replaced by INTEGER.</p>
</div>
<div>
<p style="margin-left:0.5in"> </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p style="margin-left:0.5in"> </p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</td>
</tr>
</tbody>
</table>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div></div></div>
</div>

</blockquote></div><br>