<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">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><rcolebur@SCIRES.COM></i></b> escribió:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>De: Coleburn, Randy <rcolebur@SCIRES.COM><br>Asunto: Re: [M3devel] LONGINT problem?<br>Para: "m3devel" <m3devel@elegosoft.com>, "Ken Durocher" <kcdurocher@gmail.com><br>Fecha: jueves, 14 de julio, 2011 18:15<br><br><div id="yiv1277064554"><style><!--
#yiv1277064554
_filtered #yiv1277064554 {font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;}
_filtered #yiv1277064554 {font-family:Calibri;panose-1:2 15 5 2 2 2 4 3 2 4;}
_filtered #yiv1277064554 {font-family:Tahoma;panose-1:2 11 6 4 3 5 4 4 2 4;}
#yiv1277064554
#yiv1277064554 p.yiv1277064554MsoNormal, #yiv1277064554 li.yiv1277064554MsoNormal, #yiv1277064554 div.yiv1277064554MsoNormal
{margin:0in;margin-bottom:.0001pt;font-size:12.0pt;font-family:"serif";}
#yiv1277064554 a:link, #yiv1277064554 span.yiv1277064554MsoHyperlink
{color:blue;text-decoration:underline;}
#yiv1277064554 a:visited, #yiv1277064554 span.yiv1277064554MsoHyperlinkFollowed
{color:purple;text-decoration:underline;}
#yiv1277064554 span.yiv1277064554apple-tab-span
{}
#yiv1277064554 span.yiv1277064554EmailStyle18
{font-family:"sans-serif";color:#1F497D;}
#yiv1277064554 .yiv1277064554MsoChpDefault
{}
_filtered #yiv1277064554 {margin:1.0in 1.0in 1.0in 1.0in;}
#yiv1277064554 div.yiv1277064554WordSection1
{}
--></style><div class="yiv1277064554WordSection1"><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">Ken:</span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);"> </span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">On what platform (OS and CPU) are you building and running your Modula-3 program?</span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);"> </span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">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 class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);"> </span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">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 class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);"> </span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">Regards,</span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);">Randy
Coleburn</span></p><p class="yiv1277064554MsoNormal"><span style="font-size: 11pt; font-family: "sans-serif"; color: rgb(31, 73, 125);"> </span></p><div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;"><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><b><span style="font-size: 10pt; font-family: "sans-serif";">From:</span></b><span style="font-size: 10pt; font-family: "sans-serif";"> Ken Durocher [mailto:kcdurocher@gmail.com] <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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p><div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">#include <stdio.h></p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">#include <stdlib.h></p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">#include <stdint.h></p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">/* should be 64-bit integers if going over 1 billion */</p></div><div><p class="yiv1277064554MsoNormal"
style="margin-left: 0.5in;">typedef unsigned long xint;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">#define FMT "%lu"</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">xint total, prim, max_peri;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">xint U[][9] = {{ 1, -2, 2, 2, -1, 2, 2, -2, 3},</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>{ 1, 2, 2, 2, 1, 2, 2, 2, 3},</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span
class="yiv1277064554apple-tab-span"> </span>{-1, 2, 2, -2, 1, 2, -2, 2, 3}};</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">void new_tri(xint in[])</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">{</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>int i;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>xint t[3], p = in[0] + in[1] + in[2];</p></div><div><p
class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>if (p > max_peri) return;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>prim ++;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>/* for every primitive triangle, its multiples would be right-angled too;</p></div><div><p class="yiv1277064554MsoNormal"
style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>* count them up to the max perimeter */</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>total += max_peri / p;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>/* recursively produce next tier by multiplying the matrices */</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>for (i = 0; i < 3; i++)
{</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>t[0] = U[i][0] * in[0] + U[i][1] * in[1] + U[i][2] * in[2];</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>t[1] = U[i][3] * in[0] + U[i][4] * in[1] + U[i][5] * in[2];</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>t[2] = U[i][6] * in[0] + U[i][7] * in[1] + U[i][8] *
in[2];</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>new_tri(t);</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>}</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">}</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">int main()</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">{</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span
class="yiv1277064554apple-tab-span"> </span>xint seed[3] = {3, 4, 5};</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>for (max_peri = 10; max_peri <= 100000000; max_peri *= 10) {</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>total = prim = 0;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span
class="yiv1277064554apple-tab-span"> </span>new_tri(seed);</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>printf(<span class="yiv1277064554apple-tab-span"> </span>"Up to "FMT": "FMT" triples, "FMT" primitives.\n",</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span
class="yiv1277064554apple-tab-span"> </span>max_peri, total, prim);</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>}</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"><span class="yiv1277064554apple-tab-span"> </span>return 0;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">}</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">The output from that code is:</p></div><div><p
class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 10: 0 triples, 0 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 100: 17 triples, 7 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 1000: 325 triples, 70 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 10000: 4858 triples, 703 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 100000: 64741 triples, 7026 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 1000000: 808950 triples, 70229 primitives.</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Up to 10000000: 9706567 triples, 702309 primitives.</p></div><div><p class="yiv1277064554MsoNormal"
style="margin-left: 0.5in;">Up to 100000000: 113236940 triples, 7023027 primitives.</p></div></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Note this output corresponds with the INTEGER output.</p></div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">On Thu, Jul 14, 2011 at 5:17 PM, Jay K <<a rel="nofollow" ymailto="mailto:jay.krell@cornell.edu" target="_blank" href="/mc/compose?to=jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:</p><div><div><p class="yiv1277064554MsoNormal" style="margin-right: 0in; margin-bottom: 12pt; margin-left: 0.5in;">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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in; text-align: center;" align="center"><hr align="center" size="2" width="100%"></div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">Date: Thu, 14 Jul 2011 16:26:05 -0500<br>From: <a rel="nofollow" ymailto="mailto:kcdurocher@gmail.com" target="_blank" href="/mc/compose?to=kcdurocher@gmail.com">kcdurocher@gmail.com</a><br>To: <a rel="nofollow"
ymailto="mailto:m3devel@elegosoft.com" target="_blank" href="/mc/compose?to=m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: [M3devel] LONGINT problem?</p><div><div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">MODULE PyTriples EXPORTS Main;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">IMPORT IO, Fmt;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">VAR tcnt, pcnt, max, i: LONGINT;</p></div><div><p
class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">PROCEDURE NewTriangle(a, b, c: LONGINT; VAR tcount, pcount: LONGINT) =</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> VAR perim := a + b + c; </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> BEGIN</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> IF perim <= max THEN</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> pcount := pcount + 1L;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> tcount := tcount + max DIV perim;</p></div><div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> END;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> END NewTriangle;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">BEGIN</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">i := 100L;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left:
0.5in;">REPEAT</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> max := i;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> tcnt := 0L;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> pcnt := 0L;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> NewTriangle(3L, 4L, 5L, tcnt, pcnt);</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> IO.Put(Fmt.LongInt(i) & ": " & Fmt.LongInt(tcnt) & " Triples, " &</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> Fmt.LongInt(pcnt) & " Primitives\n");</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> i := i * 10L;</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">UNTIL i = 10000000L;</p></div><div><p class="yiv1277064554MsoNormal"
style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">END PyTriples.</p></div></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">This outputs:</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">100: 17 Triples, 7 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">1000: 325 Triples, 70 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">10000: 0858 Triples, 703 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">100000: 40701 Triples, 7024 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">1000000: 808950 Triples, 70229
Primitives</p></div></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div><div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">100: 17 Triples, 7 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">1000: 325 Triples, 70 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">10000: 4858 Triples, 703 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">100000: 64741 Triples, 7026 Primitives</p></div><div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;">1000000: 808950 Triples, 70229 Primitives</p></div></div><div><p class="yiv1277064554MsoNormal"
style="margin-left: 0.5in;"> </p></div><div><p class="yiv1277064554MsoNormal" 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 class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div></div></div></div></div></div></div><p class="yiv1277064554MsoNormal" style="margin-left: 0.5in;"> </p></div></div></div></blockquote></td></tr></table>