<?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 Can someone explain Math.fmod() vs using a % operator? in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551144#M55808</link>
    <description>&lt;P&gt;&lt;I&gt;[ FlexSim 20.2.3 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Working on a decision point in Flexscript I wanted to use a modulo math operator like I can within Excel. I started tinkering with this:&lt;/P&gt;
 &lt;P&gt;if (current.labels.assert("roundRobinVal", 1).value % 2) == 0) {...then do stuff...}&lt;/P&gt;
 &lt;P&gt;But no matter what I did the % did not seem to behave like I anticipated.&lt;/P&gt;
 &lt;P&gt;I then found Math.fmod() and made this:&lt;/P&gt;
 &lt;P&gt;if (Math.fmod(current.labels.assert("roundRobinVal", 1).value, 2) == 0) {...then do stuff...}&lt;/P&gt;
 &lt;P&gt;and it worked perfectly.&lt;/P&gt;
 &lt;P&gt;I am incrementing the roundRobinVal after the if().&lt;/P&gt;
 &lt;P&gt;I also don't understand the ", 1" in the latter portion of the .assert().&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 01 Dec 2020 15:19:12 GMT</pubDate>
    <dc:creator>jonathan_s3</dc:creator>
    <dc:date>2020-12-01T15:19:12Z</dc:date>
    <item>
      <title>Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551144#M55808</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 20.2.3 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Working on a decision point in Flexscript I wanted to use a modulo math operator like I can within Excel. I started tinkering with this:&lt;/P&gt;
 &lt;P&gt;if (current.labels.assert("roundRobinVal", 1).value % 2) == 0) {...then do stuff...}&lt;/P&gt;
 &lt;P&gt;But no matter what I did the % did not seem to behave like I anticipated.&lt;/P&gt;
 &lt;P&gt;I then found Math.fmod() and made this:&lt;/P&gt;
 &lt;P&gt;if (Math.fmod(current.labels.assert("roundRobinVal", 1).value, 2) == 0) {...then do stuff...}&lt;/P&gt;
 &lt;P&gt;and it worked perfectly.&lt;/P&gt;
 &lt;P&gt;I am incrementing the roundRobinVal after the if().&lt;/P&gt;
 &lt;P&gt;I also don't understand the ", 1" in the latter portion of the .assert().&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 15:19:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551144#M55808</guid>
      <dc:creator>jonathan_s3</dc:creator>
      <dc:date>2020-12-01T15:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551145#M55809</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;The 1 is the initial value of the label in the assert -so the value it will take if it didn't exist.&lt;/P&gt;&lt;P&gt;The % operator should work exactly as fmod - can you post an example?&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 15:28:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551145#M55809</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2020-12-01T15:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551146#M55810</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;This works like I intended:&lt;/P&gt;
 &lt;P&gt; if (Math.fmod(current.labels.assert("roundRobinVal", 1).value, 2) == 0) &lt;/P&gt;
 &lt;P&gt; {newDest = current.outObjects[1];}&lt;/P&gt;
 &lt;P&gt; else &lt;/P&gt;
 &lt;P&gt; {newDest = current.outObjects[2];}&lt;/P&gt;
 &lt;P&gt; current.labels.assert("roundRobinVal", 1).value++;&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
 &lt;P&gt;This did not:&lt;/P&gt;
 &lt;P&gt;if ((current.labels.assert("roundRobinVal", 1).value % 2) == 0)&lt;/P&gt;
 &lt;P&gt; {newDest = current.outObjects[1];}&lt;/P&gt;
 &lt;P&gt; else &lt;/P&gt;
 &lt;P&gt; {newDest = current.outObjects[2];}&lt;/P&gt;
 &lt;P&gt; current.labels.assert("roundRobinVal", 1).value++;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 15:32:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551146#M55810</guid>
      <dc:creator>jonathan_s3</dc:creator>
      <dc:date>2020-12-01T15:32:47Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551147#M55811</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;I meant in a model where we can step through and see if something funky is happening, since the description you gave is perfect and should work as far as I can tell.  &lt;/P&gt;&lt;P&gt;You could try stepping through with the debugger and put expressions in the watch list to see what everything is evaluating to.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 15:41:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551147#M55811</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2020-12-01T15:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551148#M55812</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I've already implemented and saved over using Math.fmod() and it's working now.&lt;/P&gt;
 &lt;P&gt;What it seemed to be doing is that the even values never evaluated to a 0 remainder with "% 2".&lt;/P&gt;
 &lt;P&gt;As far as the debugger I haven't used that yet. I'm not sure how to put in breakpoints and watch specific variables in flexsim.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 15:58:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551148#M55812</guid>
      <dc:creator>jonathan_s3</dc:creator>
      <dc:date>2020-12-01T15:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551149#M55813</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Understood.  I really recommend the debugger - it takes out the mystery of many situatons and is pretty simple to use.  If you want help on that there's the documentation &lt;A rel="noopener noreferrer" href="https://docs.flexsim.com/en/20.2/Reference/CodingInFlexSim/Debugging/" target="_blank"&gt;here &lt;/A&gt;or you can reach out for support.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 16:04:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551149#M55813</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2020-12-01T16:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551150#M55814</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;While I'm thinking about it, can you step me through the logic of:&lt;/P&gt;
 &lt;P&gt;current.outObjects[(current.labels.assert("roundRobinVal", 1).value++ - 1) % current.outObjects.length + 1];&lt;/P&gt;
 &lt;P&gt;as in does it evaluate the .value++ and -1 before or after the %. &lt;/P&gt;
 &lt;P&gt;The way it reads left to right it would read the roundRobinVal (asserting it to 1 if it did not exist already), then increment it by 1, then -1, then divide it by "current.outObjects.length + 1" to get the final value. But that would mean the .value++ -1 would be self defeating so that's no right. I assume the ++ is done after it evaluates the %.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 16:18:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551150#M55814</guid>
      <dc:creator>jonathan_s3</dc:creator>
      <dc:date>2020-12-01T16:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551151#M55815</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;It's incremented after the expression is evaluated.  There's no preincrement yet in flexscript afaik.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 17:16:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551151#M55815</guid>
      <dc:creator>jason_lightfoot_adsk</dc:creator>
      <dc:date>2020-12-01T17:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551152#M55816</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;The F in fmod stands for float and doesn't round to the nearest integer like % does, for example:&lt;/P&gt;&lt;PRE&gt;3.4 % 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &amp;nbsp; &amp;nbsp;1
Math.fmod(3.4, 2) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// &amp;nbsp; &amp;nbsp;1.4&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 17:38:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551152#M55816</guid>
      <dc:creator>Matthew_Gillespie</dc:creator>
      <dc:date>2020-12-01T17:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can someone explain Math.fmod() vs using a % operator?</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551153#M55817</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;That makes sense with some of the behavior I was seeing. I had been wondering if it was something like that.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Dec 2020 17:42:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/can-someone-explain-math-fmod-vs-using-a-operator/m-p/13551153#M55817</guid>
      <dc:creator>jonathan_s3</dc:creator>
      <dc:date>2020-12-01T17:42:19Z</dc:date>
    </item>
  </channel>
</rss>

