{"id":47,"date":"2017-09-11T13:09:51","date_gmt":"2017-09-11T16:09:51","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=47"},"modified":"2017-09-11T13:09:51","modified_gmt":"2017-09-11T16:09:51","slug":"arith-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/arith-f\/","title":{"rendered":"arith.f"},"content":{"rendered":"<pre>c &lt;html&gt;\r\nc &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt;\r\nc &lt;body&gt;\r\nc &lt;pre&gt;\r\nc\r\nc\r\nc       John Mahaffy,  Penn State University, CmpSc 201 Example\r\nc       1\/26\/96\r\nc\r\nc\r\nc   Program to demonstrate Arithmetic Assignments\r\nc\r\n      program arith\r\n      implicit none\r\nc\r\nc     declare the data types for all Fortran variables\r\nc\r\n      real r2,r3,r4,r5,r6,ans1,ans2,ans3\r\n      integer i2,i3,i4,i5,i6,ians1,ians2,ians3,ians4\r\nc\r\nc     r2 thru r6 take on the real values 2.0 thru 6.0\r\nc\r\nc     i2 thru i6 take on the integer values 2 thru 6\r\nc\r\nc     ans1, ans2, and ans3 will contain the answers from\r\nc     real arithmetic\r\nc\r\nc     ians1 thru ians4 will contain the answers from\r\nc     integer arithmetic\r\nc\r\nc\r\nc     Set initial values of the variables with 2 valid forms\r\nc     of data statements\r\nc &lt;a name=\"data\"&gt;&lt;font color=\"FF0000\"&gt; \r\n      data r2\/2.\/,r3\/3.\/,r4\/4.0\/,r5\/5.0\/\r\n      data i2,i3,i4,i5\/2,3,4,5\/\r\nc &lt;\/a&gt; &lt;\/font&gt;\r\nc\r\nc     This ends the non-executable statements, nothing above\r\nc     this point results in a machine instruction to perform\r\nc     some operation.\r\nc     Executable statements follow.\r\nc\r\nc\r\nc     The result of any integer divide is truncated to the integer\r\nc     value less than the correct decimal answer for the division\r\nc     The result of this is that changing the order of operations\r\nc     can make a big difference in the answers.  Notice how parentheses\r\nc     force more expected results\r\nc\r\n      ians1=i2*i3\/i5\r\n      ians2=i3\/i5*i2\r\n      ians3=i2*(i3\/i5)\r\n      ians4=(i3\/i5)*i2\r\n      print *, '2*3\/5 =', ians1, ', 3\/5*2 =',ians2,\r\n     &amp;  ', 2*(3\/5) =',ians3 ,', (3\/5)*2 =',ians4\r\nc\r\nc     Real arithmetic behaves more uniformly\r\nc\r\n      ans1=r2*r3\/r5\r\n      ans2=r3\/r5*r2\r\n      ans3=(r3\/r5)*r2\r\n      print *, '2.0*3.0\/5.0 =', ans1, ', 3.0\/5.0*2.0 =',ans2,\r\n     &amp;  ', (3.0\/5.0)*2.0 =',ans3\r\nc\r\nc     Watch how precedence of operations effects the following:\r\nc\r\n      ians1=i2+i5*i3**i2\r\n      ians2=i5*i3**i2+i2\r\n      ians3=i3**i2*i5+i2\r\n      print *, '2+5*3**2 =',ians1,', 5*3**2+2 =',ians2,\r\n     &amp; ', 3**2*5+2 =',ians3\r\nc\r\nc     You can mix real and integers, but watch what happens\r\nc\r\nc\r\n      ans1=r5+i3\/i2\r\n      print *, '5.0+3\/2 =',ans1\r\n\r\nc\r\nc     You can do the same thing with constants in the expression\r\nc\r\n      ans2=5.0+3\/2\r\n      print *, '5.0+3\/2 =',ans2\r\nc\r\nc     Look at what happens when I put a real in either the numerator\r\nc     or denominator of the division term\r\n      ans1=r5+i3\/r2\r\n      ans2=r5+r3\/i2\r\n      print *, '5.0+3\/2.0 =',ans1, ', 5.0+3.0\/2 =', ans2\r\nc\r\nc\r\nc     Although Fortran normally works from left to right at a given\r\nc     level of precedence (does all multiply and divide from left to\r\nc     right before moving on to adds and subtracts).  It works\r\nc     exponentiation from right to left when it hits 2 or more\r\nc     sequential exponentiation operations\r\nc\r\n      ians1= i5**i3**i2\r\n      ians2= (i5**i3)**i2\r\n      ians3= i5**(i3**i2)\r\n      print *, '5**3**2 =',ians1, ', (5**3)**2 =',ians2,\r\n     &amp;  ', 5**(3**2) =',ians3\r\nc\r\nc    When in doubt use parentheses to get the answer that you\r\nc    really want.\r\nc\r\n      stop\r\nc&lt;a name=\"end\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc &lt;\/pre&gt;\r\nc &lt;\/body&gt;\r\nc &lt;\/html&gt;\r\nc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c &lt;html&gt; c &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt; c &lt;body&gt; c &lt;pre&gt; c c c John Mahaffy, Penn State University, CmpSc 201 Example c 1\/26\/96 c c c Program to demonstrate Arithmetic Assignments c program arith implicit none c c declare the data types for all Fortran variables c real r2,r3,r4,r5,r6,ans1,ans2,ans3 integer i2,i3,i4,i5,i6,ians1,ians2,ians3,ians4 c c r2 thru r6 take [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-47","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/47\/revisions"}],"predecessor-version":[{"id":48,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/47\/revisions\/48"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}