title: Is There a Triangle Wave Function?
body: <p>in a <code>for</code>-loop with <code>%</code> to get a saw function, for example using a period of 5 printing 2 cycles would look like this:</p>
  
  <pre><code>for(auto i = 0; i &lt; 5 * 2; ++i) cout &lt;&lt; i % 5 &lt;&lt; endl;
  </code></pre>
  
  <p>Results in:</p>
  
  <blockquote>
    <p>0<br>
    1<br>
    2<br>
    3<br>
    4<br>
    0<br>
    1<br>
    2<br>
    3<br>
    4</p>
  </blockquote>
  
  <p>I want a function returns a triangle wave, so for some function <code>foo</code>:</p>
  
  <pre><code>for(auto i = 0; i &lt; 5 * 2; ++i) cout &lt;&lt; foo(i, 5) &lt;&lt; endl;
  </code></pre>
  
  <p>Would result in:</p>
  
  <blockquote>
    <p>0<br>
    1<br>
    2<br>
    1<br>
    0<br>
    0<br>
    1<br>
    2<br>
    1<br>
    0</p>
  </blockquote>
  
  <p>Is there such a function, or do I need to come up with my own?</p>