<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Integer overflow in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747393#M4952</link>
    <description>Spelling errors? Me!? Never!</description>
    <pubDate>Fri, 11 Jun 2010 15:49:51 GMT</pubDate>
    <dc:creator>Izaak_Beekman</dc:creator>
    <dc:date>2010-06-11T15:49:51Z</dc:date>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747387#M4946</link>
      <description>Please note I have corrected the typo in the thread title. 10:20 AM EST 6-11-2010&lt;BR /&gt;&lt;BR /&gt;Simple question: Does anyone know if the standard specifies what happens when integers overflow? Through some experimentation with intel 11.1.046 it looks like the value of the integer seems to wrap around. i.e&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;PRE&gt;[fortran]PROGRAM int_explode&lt;BR /&gt;IMPLICIT NONE&lt;BR /&gt;INTEGER :: my_int&lt;BR /&gt;&lt;BR /&gt;my_int = HUGE(my_int)&lt;BR /&gt;PRINT*, my_int&lt;BR /&gt;my_int = my_int + 1&lt;BR /&gt;PRINT*, my_int&lt;BR /&gt;PRINT*, -HUGE(my_int) - 1&lt;BR /&gt;IF ( my_int == -HUGE(my_int - 1) PRINT*, 'Integer overflow wraps around.'&lt;BR /&gt;END PROGRAM[/fortran]&lt;/PRE&gt; Is thisbehaviorspecified by the standard, or will relying on it result in non-portable code?&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Many thanks,&lt;/DIV&gt;&lt;DIV&gt;-Z&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Jun 2010 02:31:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747387#M4946</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-11T02:31:49Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747388#M4947</link>
      <description>The standard does not specify the behavior of such a thing. The standard does descirbe the "model" for integer data types, but that only holds as long as your computations are within the model range. You cannot depend on the behavior of code such as you show. In particular, the standard's model of integers is that the model range is symmetric around zero, which typical twos-complement binary is not. You have undoubtedly noticed that -HUGE(my_int) is not the most negative integer value.&lt;BR /&gt;&lt;BR /&gt;Intel Fortran does not have integer overflow detection.&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jun 2010 14:25:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747388#M4947</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-06-11T14:25:19Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747389#M4948</link>
      <description>Thank you so much for your reply Steve, I really appreciate it. I guess I will have to think carefully about how to implement the hash function I am working on.&lt;BR /&gt;&lt;BR /&gt;-Z</description>
      <pubDate>Fri, 11 Jun 2010 14:27:46 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747389#M4948</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-11T14:27:46Z</dc:date>
    </item>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747390#M4949</link>
      <description>To expand on Steves reply:&lt;BR /&gt;&lt;BR /&gt;Two's compliment arithmitic yields&lt;BR /&gt;&lt;BR /&gt;my_int = HUGE(my_int)&lt;BR /&gt;if(my_int .ne. 0) print "this will print"&lt;BR /&gt;my_int = my_int + 1&lt;BR /&gt;if(my_int .ne. 0) print "this will print"&lt;BR /&gt;if(my_int .lt. 0) print "this will print (integer overflow)"&lt;BR /&gt;if(my_int .eq. -my_int) print "this will print"&lt;BR /&gt;&lt;BR /&gt;The integer overflow wraps to the largest negative number.&lt;BR /&gt;Depending on your deffinition of 0, this may also be -0.&lt;BR /&gt;&lt;BR /&gt;Jim&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Jun 2010 15:25:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747390#M4949</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-06-11T15:25:47Z</dc:date>
    </item>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747391#M4950</link>
      <description>Thanks Jim,&lt;BR /&gt;I know what two's complement arithmatic is ;-)&lt;BR /&gt;-Z</description>
      <pubDate>Fri, 11 Jun 2010 15:31:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747391#M4950</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-11T15:31:04Z</dc:date>
    </item>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747392#M4951</link>
      <description>Compliments are always welcome, but note that we're discussing two's complement arithmetic. :D</description>
      <pubDate>Fri, 11 Jun 2010 15:39:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747392#M4951</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-06-11T15:39:50Z</dc:date>
    </item>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747393#M4952</link>
      <description>Spelling errors? Me!? Never!</description>
      <pubDate>Fri, 11 Jun 2010 15:49:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747393#M4952</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-11T15:49:51Z</dc:date>
    </item>
    <item>
      <title>Integer overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747394#M4953</link>
      <description>If you require standard defined behavior with wrap, you must use C unsigned int, preferably C99 uint64_t . As ifort (like most Fortran compilers) has no unsigned integer, you must take care in accordance with these data types being reinterpreted as signed when seen from Fortran.</description>
      <pubDate>Fri, 11 Jun 2010 15:50:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747394#M4953</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2010-06-11T15:50:53Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747395#M4954</link>
      <description>&lt;DIV id="tiny_quote"&gt;&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1276282412059="81" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=310779" href="https://community.intel.com/en-us/profile/310779/" class="basic"&gt;zbeekman&lt;/A&gt;&lt;/DIV&gt;&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;Thank you so much for your reply Steve, I really appreciate it. I guess I will have to think carefully about how to implement the hash function I am working on.&lt;BR /&gt;&lt;BR /&gt;-Z&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Implement your hash functions in C&lt;BR /&gt;&lt;BR /&gt;Or stay in Fortran but implement as user defined type with "member functions" for generation, manipulation, comparisons etc... (forcing you to use module routines as opposed to integer functions/expressions)&lt;BR /&gt;&lt;BR /&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jun 2010 18:57:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747395#M4954</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-06-11T18:57:28Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747396#M4955</link>
      <description>Or compute in INTEGER(8) and mask off the upper bits? I don't know if that helps.</description>
      <pubDate>Fri, 11 Jun 2010 20:06:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747396#M4955</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-06-11T20:06:59Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747397#M4956</link>
      <description>It seems to me that hash functions are just a deterministic bit scrambling. The goal is to take objects which might be similar or related (i.e. have a nearly matching machine representation) and to scater in a uniform distribution, avoiding collisions. In this regard they seem to be akin to random number generators. After some quick research it looks like perhaps I can use the transfer function to transfer strings (in chunks of 4 characters) to integers (4 Byte integers). From this array of integers, I could use bit manipulations to mix the bits up and reduce the arry of integers to a single integer, then perform the modular division. This is akin to the "Marsaglia shift register" random number generation technique. The bit manipulation functions should be fast, and efficient and mixing in all the information in the string. If anyone has doubts about this approach please let me know. I am going to do some testing and report back on what I find.</description>
      <pubDate>Fri, 11 Jun 2010 21:22:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747397#M4956</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-11T21:22:25Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747398#M4957</link>
      <description>Several possibilities:&lt;BR /&gt;&lt;BR /&gt;For portability, as already suggested, implement in C.&lt;BR /&gt;&lt;BR /&gt;Or, Michel Olagnon has a Fortran module to provide a 32-bit unsigned type: look for unsi32.f90.Z at &lt;A href="http://www.ifremer.fr/ditigo/molagnon/fortran90/engfaq.html" target="_blank"&gt;http://www.ifremer.fr/ditigo/molagnon/fortran90/engfaq.html&lt;/A&gt; or ftp://ftp.ifremer.fr/ifremer/ditigo/fortran90/. I haven't tested it, can't say anything about the speed, etc.&lt;BR /&gt;&lt;BR /&gt;While integer overflow goes beyond the standard, the overflow behavior of unsigned integers will be extremely common, approaching universal, though not guaranteed. Once you have done your calculation, you can assign the result to a larger integer type. Then either mask off the bits (suggested above), or if the value is negative, add a correcting offset. Depending on your needs re guaranteed portability, this method might work.&lt;BR /&gt;&lt;BR /&gt;I wish that Fortran had unsigned integers.... in my work I have several uses. Apparently the standard's committee has declined to add them despite numerous requests. One compiler has them as an extension.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[fortran]&lt;PRE name="code" class="fortran"&gt;program IntTest

   implicit none
   
   integer, parameter :: Int32 = selected_int_kind (8)
   integer, parameter :: Int64 = selected_int_kind (18)
   
   integer (Int32) :: RegularInt
   integer (Int64) :: BigInt1, BigInt2
   
   write (*, *) huge (RegularInt), huge (BigInt1)
   
   RegularInt = 2147483645
   RegularInt = RegularInt + 10;
   BigInt1 = RegularInt
   BigInt2 = RegularInt
   if (BigInt1 &amp;lt; 0) BigInt1 = BigInt1 + 4294967296_Int64
   BigInt2 = iand ( BigInt2, int (Z'FFFFFFFF', Int64) )
   write (*, *) RegularInt, BigInt1, BigInt2
   
   
   RegularInt = 2147483645
   RegularInt = 2 * RegularInt + 10;
   BigInt1 = RegularInt
   BigInt2 = RegularInt
   if (BigInt1 &amp;lt; 0) BigInt1 = BigInt1 + 4294967296_Int64
   BigInt2 = iand ( BigInt2, int (Z'FFFFFFFF', Int64) )
   write (*, *) RegularInt, BigInt1, BigInt2
   

   stop

end program IntTest[/fortran]&lt;/PRE&gt; &lt;BR /&gt;&lt;/PRE&gt; &lt;BR /&gt;Compare the results to:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]#include &lt;STDIO.H&gt;
#include &lt;STDINT.H&gt;

int main (void) {

   uint32_t  RegularInt1, RegularInt2;

   RegularInt1 = 2147483645;
   RegularInt2 = RegularInt1 + 10;
   printf ( "%un", RegularInt2 );
   
   
   RegularInt1 = 2147483645;
   RegularInt2 = 2 * RegularInt1 + 10;
   printf ( "%un", RegularInt2 );
   
   return 0;

}[/cpp]&lt;/STDINT.H&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Jun 2010 04:42:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747398#M4957</guid>
      <dc:creator>msbriggs</dc:creator>
      <dc:date>2010-06-12T04:42:07Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747399#M4958</link>
      <description>I agree, it would be a nice addition. I have decided to approach hashing using bit manipulation rather than the linear congruential generator approach. This way I can ensure a thorough mixing of bits without worrying about holes in the standard and integer overflow. But thanks for your post!</description>
      <pubDate>Sat, 12 Jun 2010 13:27:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747399#M4958</guid>
      <dc:creator>Izaak_Beekman</dc:creator>
      <dc:date>2010-06-12T13:27:54Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747400#M4959</link>
      <description>With the extension, the Fortran code for unsigned integers becomes as simple as the C:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE name="code"&gt;program SunIntTest

   implicit none
   
   integer, parameter :: Int32 = selected_int_kind (8)
   
   integer (Int32) :: RegularInt
   unsigned (kind=4) :: UnsignedInt32
   
   write (*, *) huge (RegularInt), huge (UnsignedInt32)
   
   UnsignedInt32 = 2147483645U_4
   UnsignedInt32 = UnsignedInt32 + 10U_4;
   write (*, *) UnsignedInt32
   
   UnsignedInt32 = 2147483645U_4
   UnsignedInt32 = 2U_4 * UnsignedInt32 + 10U_4;
   write (*, *) UnsignedInt32
   
   stop

end program SunIntTest&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The output is:&lt;BR /&gt;&lt;BR /&gt; 2147483647 4294967295&lt;BR /&gt;2147483655&lt;BR /&gt;4&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Intel, any interest in also adding this extension?   Maybe if enough vendors did, it would get added to the standard. &lt;BR /&gt;Unsigned integers would make it easier to write certain algorithms and data handlers.&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jun 2010 05:00:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747400#M4959</guid>
      <dc:creator>msbriggs</dc:creator>
      <dc:date>2010-06-13T05:00:26Z</dc:date>
    </item>
    <item>
      <title>Intel overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747401#M4960</link>
      <description>At this time we are not interested in adding this extension. The standards committee has debated this one quite a bit and rejected it. I don't see that changing anytime soon. We have our hands quite full just finishing the standard.</description>
      <pubDate>Mon, 14 Jun 2010 13:31:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Integer-overflow/m-p/747401#M4960</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-06-14T13:31:01Z</dc:date>
    </item>
  </channel>
</rss>

