<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Floating point modulo?]]></title><description><![CDATA[<ol>
<li>
<p>Is <code>[expr fmod($f1, something)]</code> the only way to get a floating-point modulo?</p>
</li>
<li>
<p>This is a bit amusing: <code>/</code> and <code>div</code> are floating-point and integer division, respectively. So one might expect <code>%</code> and <code>mod</code> to be floating-point and integer modulo, respectively. But someone seems to have had a sense of humor some years ago?</p>
</li>
</ol>
<p><img src="/uploads/files/1573001218035-pd-float-mod.png" alt="pd-float-mod.png" class="img-responsive img-markdown" /></p>
<p>hjh</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 06:42:05 GMT</lastBuildDate><atom:link href="http://forum.pdpatchrepo.info/topic/12427.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Nov 2019 00:47:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Floating point modulo? on Wed, 06 Nov 2019 00:47:37 GMT]]></title><description><![CDATA[<ol>
<li>
<p>Is <code>[expr fmod($f1, something)]</code> the only way to get a floating-point modulo?</p>
</li>
<li>
<p>This is a bit amusing: <code>/</code> and <code>div</code> are floating-point and integer division, respectively. So one might expect <code>%</code> and <code>mod</code> to be floating-point and integer modulo, respectively. But someone seems to have had a sense of humor some years ago?</p>
</li>
</ol>
<p><img src="/uploads/files/1573001218035-pd-float-mod.png" alt="pd-float-mod.png" class="img-responsive img-markdown" /></p>
<p>hjh</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo</guid><dc:creator><![CDATA[ddw_music]]></dc:creator><pubDate>Wed, 06 Nov 2019 00:47:37 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Thu, 07 Nov 2019 20:28:36 GMT]]></title><description><![CDATA[<p>Both mod and % produce remainders for integer division in C and C++. Pd is written in C; since it uses the &quot;%&quot; operator internally to produce the output for <code>[%]</code> that is the operation you get.</p>
<p>It may seem like humor in retrospect given that Javascript, for example, gives double-precision floating point output for the &quot;%&quot; op. But I don't think it appeared that Javascript would run on billions of devices in the late 90s.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/2</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/2</guid><dc:creator><![CDATA[jancsika]]></dc:creator><pubDate>Thu, 07 Nov 2019 20:28:36 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Fri, 08 Nov 2019 07:46:50 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/jancsika">@jancsika</a> &quot;Both mod and % produce remainders for integer division in C and C++. Pd is written in C; since it uses the &quot;%&quot; operator internally to produce the output for [%] that is the operation you get.&quot;</p>
<p>OK, fair, but... by analogy, we might go looking for a Pd object that uses fmod() internally:</p>
<pre><code> fmod 4
... couldn't create
</code></pre>
<p>The specific use case was a demonstration for a class of crossfading between multiple wavetables (in the trendy Massive or Serum softsynth way). The crossfade coefficients are based on <code>fmod(wavetable_index, 2)</code> and really do need the fractional part.</p>
<p>hjh</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/3</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/3</guid><dc:creator><![CDATA[ddw_music]]></dc:creator><pubDate>Fri, 08 Nov 2019 07:46:50 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Fri, 08 Nov 2019 12:47:16 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/ddw_music">@ddw_music</a> you can get rid of the floating point when multiplying by 10s and dividing at the end.<br />
for example:</p>
<pre><code>
[* 10000] 
[mod 20000]
[/ 10000]

</code></pre>
<p>fmod() you can use in [expr], [expr~] and [fexpr~]</p>
<p>And notice in the helpfile of [expr] &gt;&gt; [pd [expr] examples] the use of floats and integers</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/4</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/4</guid><dc:creator><![CDATA[lacuna]]></dc:creator><pubDate>Fri, 08 Nov 2019 12:47:16 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Fri, 08 Nov 2019 17:28:05 GMT]]></title><description><![CDATA[<blockquote>
<p>OK, fair, but... by analogy, we might go looking for a Pd object that uses fmod() internally:</p>
</blockquote>
<p>It should have had one.</p>
<p>Would probably be nice to give a suggestion on error for common things like expr functions and other common errors the way git's CLI tools do.</p>
<p>I added a feature request to Purr Data for this:</p>
<p><a href="https://git.purrdata.net/jwilkes/purr-data/issues/561" rel="nofollow">https://git.purrdata.net/jwilkes/purr-data/issues/561</a></p>
<p>Edit: and to be clear-- I don't think Pd Vanilla needs to add all the expr functions as internal classes. That could easily cause backwards compatibility issues with externals or private abstraction collections for little benefit.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/5</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/5</guid><dc:creator><![CDATA[jancsika]]></dc:creator><pubDate>Fri, 08 Nov 2019 17:28:05 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Fri, 08 Nov 2019 18:54:28 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/ddw_music">@ddw_music</a>  Not internal, but not wildly expensive either.....<br />
<a href="/uploads/files/1573239212122-creb-fmod.zip">creb-fmod.zip</a><br />
David.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/6</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/6</guid><dc:creator><![CDATA[whale-av]]></dc:creator><pubDate>Fri, 08 Nov 2019 18:54:28 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Fri, 08 Nov 2019 20:18:56 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/whale-av">@whale-av</a> Yes, creb is actually loaded by default in Purr Data.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/7</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/7</guid><dc:creator><![CDATA[jancsika]]></dc:creator><pubDate>Fri, 08 Nov 2019 20:18:56 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Sat, 09 Nov 2019 01:21:36 GMT]]></title><description><![CDATA[<p>Thanks for the further comments.</p>
<p>I know you can multiply-mod-divide and get fractions. The broader point is about usability. It's a difficult trade-off -- adding more features for the sake of usability creates maintenance problems (which, to be honest, we see in SuperCollider-land), but keeping things light and maintainable means that easy things (fmod) become harder than they should be (concrete impact here is, I will have to explain to a classroom full of not particularly technical students why they can't use a simple, dedicated object for floating-point modulo when there are simple, dedicated objects for the other basic operators -- too much fine print gets old after awhile -- or let them use it Purr-Data now, and take it away from them later when I have to switch them to vanilla Pd so that they can use Gem on Mac).</p>
<p>hjh</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/8</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/8</guid><dc:creator><![CDATA[ddw_music]]></dc:creator><pubDate>Sat, 09 Nov 2019 01:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to Floating point modulo? on Sun, 10 Nov 2019 05:03:53 GMT]]></title><description><![CDATA[<p>Just thought I'd point out that the difference between mod and % is how they handle negative values.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/9</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/12427/floating-point-modulo/9</guid><dc:creator><![CDATA[myQwil]]></dc:creator><pubDate>Sun, 10 Nov 2019 05:03:53 GMT</pubDate></item></channel></rss>