<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Debug School: ashley</title>
    <description>The latest articles on Debug School by ashley (@ashley_3a98ae2065f34c9ceb).</description>
    <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb</link>
    <image>
      <url>https://www.debug.school/images/a23IWoE84k3wsCHVCgeOZQV2XzCEncXVRnzYonQeiG0/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly93d3cu/ZGVidWcuc2Nob29s/L3VwbG9hZHMvdXNl/ci9wcm9maWxlX2lt/YWdlLzEwMDAvYWM0/MmQzNjUtNmFlNC00/NGI4LThmOTUtZmE4/N2IwZDk4OTE0LnBu/Zw</url>
      <title>Debug School: ashley</title>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://www.debug.school/feed/ashley_3a98ae2065f34c9ceb"/>
    <language>en</language>
    <item>
      <title>Fixed-Rate Mortgage Amortization in Code: Principal vs Interest Breakdown and Edge Cases</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Thu, 19 Nov 2026 06:07:52 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/fixed-rate-mortgage-amortization-in-code-principal-vs-interest-breakdown-and-edge-cases-4912</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/fixed-rate-mortgage-amortization-in-code-principal-vs-interest-breakdown-and-edge-cases-4912</guid>
      <description>&lt;p&gt;Fixed-rate mortgage schedules (the French amortization system) maintain a constant monthly payment $P$. However, the internal distribution between interest payment $J_k$ and principal reduction $A_k$ shifts continuously over the term.&lt;/p&gt;

&lt;h3&gt;
  
  
  Formula for Fixed Monthly Payment
&lt;/h3&gt;

&lt;p&gt;Given principal loan amount $PV$, monthly interest rate $i$, and total number of months $n$:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;P = PV * (i * ((1 + i) ** n)) / (((1 + i) ** n) - 1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For each month $k$:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Interest: $J_k = S_{k-1} \cdot i$&lt;/li&gt;
&lt;li&gt;Principal Amortization: $A_k = P - J_k$&lt;/li&gt;
&lt;li&gt;Remaining Balance: $S_k = S_{k-1} - A_k$&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Python Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_amortization_schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;annual_rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;
    &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;annual_rate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;12.0&lt;/span&gt;
    &lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;factor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pv&lt;/span&gt;
    &lt;span class="n"&gt;schedule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;interest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;
        &lt;span class="n"&gt;amortization&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payment&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;interest&lt;/span&gt;
        &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;amortization&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;amortization&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;
            &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;

        &lt;span class="n"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;month&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;payment&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;interest&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;interest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;amortization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amortization&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;balance&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;schedule&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verification and Schedule Inspection
&lt;/h3&gt;

&lt;p&gt;To generate a complete month-by-month payment schedule and visualize principal vs interest decay, check the &lt;a href="https://www.miryori.org/tools/amortization-calculator" rel="noopener noreferrer"&gt;amortization calculator&lt;/a&gt; at Miryori.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: The author leads content at Miryori, the free online calculator suite linked above. Educational arithmetic only, not financial advice.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>APR vs APY in Code: Converting Compounding Frequencies Without Loss of Precision</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Thu, 19 Nov 2026 05:58:30 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/apr-vs-apy-in-code-converting-compounding-frequencies-without-loss-of-precision-glk</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/apr-vs-apy-in-code-converting-compounding-frequencies-without-loss-of-precision-glk</guid>
      <description>&lt;p&gt;In financial software, mixing up Annual Percentage Rate (APR) and Annual Percentage Yield (APY) is a frequent source of logic bugs. APR represents nominal interest without compounding, whereas APY measures the true annual return taking compounding frequency into account.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deriving APY from APR
&lt;/h3&gt;

&lt;p&gt;For a nominal rate $r$ compounded $m$ times per year:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;APY = ((1 + r / m) ** m) - 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For continuous compounding ($m \to \infty$):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;APY_continuous = exp(r) - 1&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Converting APY Back to Nominal APR
&lt;/h3&gt;

&lt;p&gt;To determine the nominal periodic rate required to achieve a target APY:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;r = m * (((1 + APY) ** (1 / m)) - 1)&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Python Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;apr_to_apy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Compounding frequency must be &amp;gt;= 0.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expm1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;apr&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;apy_to_apr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;apy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Compounding frequency must be &amp;gt; 0.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;apy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verification and Simulation
&lt;/h3&gt;

&lt;p&gt;To convert between APR and APY across different compounding schedules, try the &lt;a href="https://www.miryori.org/tools/apy-calculator" rel="noopener noreferrer"&gt;APY calculator&lt;/a&gt; at Miryori.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: The author leads content at Miryori, the free online calculator suite linked above. Educational arithmetic only, not financial advice.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Modeling Compound Interest in Code: Why Loop Iteration Accumulates Floating-Point Drift</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Thu, 19 Nov 2026 05:58:07 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/modeling-compound-interest-in-code-why-loop-iteration-accumulates-floating-point-drift-18j6</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/modeling-compound-interest-in-code-why-loop-iteration-accumulates-floating-point-drift-18j6</guid>
      <description>&lt;p&gt;When building financial algorithms or growth projections, developers often write a simple loop that multiplies capital by $(1 + r/12)$ at each step. Over multi-year horizons, this iterative accumulation in IEEE 754 floating-point arithmetic introduces drift compared to the exact mathematical closed form.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Closed-Form Equation
&lt;/h3&gt;

&lt;p&gt;For initial capital $PV$, nominal annual interest rate $r$, and $m$ compounding periods per year, the compound value after $t$ years is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;FV = PV * ((1 + r / m) ** (m * t))&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The effective annual rate (APY) derived from $m$ compounding periods is:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;APY = ((1 + r / m) ** m) - 1&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Comparison of Compounding Frequency (on $10,000 at 6% Nominal Rate)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Compounding Frequency ($m$)&lt;/th&gt;
&lt;th&gt;Formula&lt;/th&gt;
&lt;th&gt;APY&lt;/th&gt;
&lt;th&gt;Final Balance ($1 Year)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Annual ($m = 1$)&lt;/td&gt;
&lt;td&gt;$(1 + 0.06)^1 - 1$&lt;/td&gt;
&lt;td&gt;$6.0000\%$&lt;/td&gt;
&lt;td&gt;$10,600.00&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Quarterly ($m = 4$)&lt;/td&gt;
&lt;td&gt;$(1 + 0.015)^4 - 1$&lt;/td&gt;
&lt;td&gt;$6.1364\%$&lt;/td&gt;
&lt;td&gt;$10,613.64&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Monthly ($m = 12$)&lt;/td&gt;
&lt;td&gt;$(1 + 0.005)^{12} - 1$&lt;/td&gt;
&lt;td&gt;$6.1678\%$&lt;/td&gt;
&lt;td&gt;$10,616.78&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Daily ($m = 365$)&lt;/td&gt;
&lt;td&gt;$(1 + 0.06/365)^{365} - 1$&lt;/td&gt;
&lt;td&gt;$6.1831\%$&lt;/td&gt;
&lt;td&gt;$10,618.31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Continuous ($m \to \infty$)&lt;/td&gt;
&lt;td&gt;$e^{0.06} - 1$&lt;/td&gt;
&lt;td&gt;$6.1837\%$&lt;/td&gt;
&lt;td&gt;$10,618.37&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Python Implementation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_compound_interest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pv&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;annual_rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;annual_rate&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Invalid negative input values.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Continuous compounding
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;annual_rate&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;period_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;annual_rate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt;
    &lt;span class="n"&gt;total_periods&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;comp_freq&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;years&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pv&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.0&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;period_rate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total_periods&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Verification and Interactive Recheck
&lt;/h3&gt;

&lt;p&gt;To test custom compounding parameters and view period-by-period growth charts, verify calculations with the &lt;a href="https://www.miryori.org/tools/compound-interest-calculator" rel="noopener noreferrer"&gt;compound interest calculator&lt;/a&gt; at Miryori.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: The author leads content at Miryori, the free online calculator suite linked above. Educational arithmetic only, not financial advice.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Backing Out Sales Tax from a Total: Why T * (1 - r) Is Always Wrong</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Tue, 17 Nov 2026 05:38:54 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/backing-out-sales-tax-from-a-total-why-t-1-r-is-always-wrong-1l2p</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/backing-out-sales-tax-from-a-total-why-t-1-r-is-always-wrong-1l2p</guid>
      <description>&lt;h1&gt;
  
  
  Backing Out Sales Tax from a Total: Why T * (1 - r) Is Always Wrong
&lt;/h1&gt;

&lt;p&gt;A receipt shows a gross total of $108.00, and the local sales tax rate is 8%. A developer wants to find the pre-tax price. The most common instinct is to take 8% of $108.00 ($8.64) and subtract it to get $99.36.&lt;/p&gt;

&lt;p&gt;That answer is wrong. The actual pre-tax price was &lt;strong&gt;$100.00&lt;/strong&gt;, and the tax was &lt;strong&gt;$8.00&lt;/strong&gt;. The $8.64 calculation overstates the tax and understates the base price.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why subtraction fails
&lt;/h2&gt;

&lt;p&gt;Sales tax is calculated by adding a percentage $r$ to the &lt;strong&gt;pre-tax price&lt;/strong&gt; $P$:&lt;/p&gt;

&lt;p&gt;$$\text{Total} = P + (P \times r) = P(1 + r)$$&lt;/p&gt;

&lt;p&gt;Notice that tax is $r \times P$, not $r \times \text{Total}$.&lt;/p&gt;

&lt;p&gt;When you try to back out tax by calculating $\text{Total} \times (1 - r)$, you are applying the percentage to the larger number ($\text{Total}$). Because $8\%$ of $\$108$ is larger than $8\%$ of $\$100$, subtracting $r \times \text{Total}$ subtracts too much.&lt;/p&gt;

&lt;h2&gt;
  
  
  The correct reverse formula
&lt;/h2&gt;

&lt;p&gt;To find pre-tax price $P$ from total $T$ and tax rate $r$:&lt;/p&gt;

&lt;p&gt;$$P = \frac{T}{1 + r}$$&lt;/p&gt;

&lt;p&gt;And the tax amount $X$ is:&lt;/p&gt;

&lt;p&gt;$$X = T - P = T - \frac{T}{1 + r} = T \left(1 - \frac{1}{1 + r}\right) = T \left(\frac{r}{1 + r}\right)$$&lt;/p&gt;

&lt;h3&gt;
  
  
  Worked example
&lt;/h3&gt;

&lt;p&gt;Total $T = \$108.00$, rate $r = 8\% = 0.08$.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Pre-tax price:
$$P = \frac{108.00}{1 + 0.08} = \frac{108.00}{1.08} = \$100.00$$&lt;/li&gt;
&lt;li&gt;Tax amount:
$$X = 108.00 - 100.00 = \$8.00$$&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check: $\$100.00 \times 8\% = \$8.00$. Pre-tax $\$100.00$ + Tax $\$8.00$ = Total $\$108.00$.&lt;/p&gt;

&lt;h2&gt;
  
  
  Combined state and local tax rates
&lt;/h2&gt;

&lt;p&gt;In jurisdictions with multiple tax tiers (e.g., state sales tax 6% + city sales tax 2% + district tax 0.5% = 8.5% total):&lt;/p&gt;

&lt;p&gt;Add rates first before inverting:&lt;/p&gt;

&lt;p&gt;$$r_{\text{total}} = 0.06 + 0.02 + 0.005 = 0.085$$&lt;br&gt;
$$P = \frac{T}{1.085}$$&lt;/p&gt;

&lt;p&gt;Do &lt;strong&gt;not&lt;/strong&gt; back out each tax rate sequentially ($\frac{T}{1.06} / 1.02 ...$), as sequential division compounds the reduction incorrectly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rounding issues in e-commerce
&lt;/h2&gt;

&lt;p&gt;When line items are stored individually and tax is calculated per line vs on order total:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Line item tax sum:&lt;/strong&gt; Sum of &lt;code&gt;round(price_i * r)&lt;/code&gt; for each item.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order-level tax:&lt;/strong&gt; &lt;code&gt;round(sum(price_i) * r)&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because &lt;code&gt;sum(round(x_i)) != round(sum(x_i))&lt;/code&gt;, e-commerce systems must pick one method and apply it consistently across invoicing, cart display, and accounting exports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing sales tax calculations
&lt;/h2&gt;

&lt;p&gt;When testing checkout logic or auditing gross receipts for pre-tax numbers, a dedicated tax calculator helps verify reverse-tax and combined-rate calculations. The &lt;a href="https://www.miryori.org/tools/sales-tax-calculator" rel="noopener noreferrer"&gt;sales tax calculator&lt;/a&gt; at Miryori computes forward sales tax, reverse pre-tax amounts, and state/local combined totals client-side in the browser.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: formula breakdowns illustrate software math and do not constitute tax or accounting advice.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Modeling PTO Accrual in Code: Pay Period Drift, 27-Paycheck Years, and Cap Bounds</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Tue, 17 Nov 2026 05:36:14 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/modeling-pto-accrual-in-code-pay-period-drift-27-paycheck-years-and-cap-bounds-5clb</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/modeling-pto-accrual-in-code-pay-period-drift-27-paycheck-years-and-cap-bounds-5clb</guid>
      <description>&lt;h1&gt;
  
  
  Modeling PTO Accrual in Code: Pay Period Drift, 27-Paycheck Years, and Cap Bounds
&lt;/h1&gt;

&lt;p&gt;Paid Time Off (PTO) calculation seems like simple addition: &lt;code&gt;accrued = hours_per_period * periods&lt;/code&gt;. But when you implement accrual rules in a HRIS or payroll system, edge cases like leap years, bi-weekly pay period drift (27 paychecks in a calendar year), mid-period hire dates, and accrual caps lead to subtle balance discrepancies.&lt;/p&gt;

&lt;h2&gt;
  
  
  The accrual frequency problem
&lt;/h2&gt;

&lt;p&gt;PTO is typically awarded on one of three schedules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Per pay period:&lt;/strong&gt; Added every time payroll runs (e.g., 80-hour biweekly or semi-monthly).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monthly:&lt;/strong&gt; Added on the 1st or last day of the calendar month.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lump sum / Annual:&lt;/strong&gt; Granted at the start of the year or anniversary date.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The 27-paycheck anomaly
&lt;/h3&gt;

&lt;p&gt;Biweekly pay periods happen every 14 days ($364$ days per 26 pay periods). Because a calendar year has 365 (or 366) days, every 11 to 12 years a calendar year contains &lt;strong&gt;27 pay dates&lt;/strong&gt; instead of 26.&lt;/p&gt;

&lt;p&gt;If your accrual engine adds &lt;code&gt;annual_pto / 26&lt;/code&gt; per paycheck without checking the calendar year's pay date count, employees in a 27-paycheck year will accrue $103.8\%$ of their annual target allotment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three accrual cap models
&lt;/h2&gt;

&lt;p&gt;Employers enforce caps to limit balance liability. In code, caps must be evaluated in the exact sequence specified by policy:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Max Balance Cap (Hard Stop)
&lt;/h3&gt;

&lt;p&gt;The balance cannot exceed a maximum value $M$.&lt;br&gt;
$$\text{New Balance} = \min(\text{Current Balance} + \text{Accrued}, M)$$&lt;br&gt;
&lt;em&gt;Edge case:&lt;/em&gt; If an employee is at the cap, takes 8 hours of leave on Tuesday, and payroll runs on Friday, does the leave deduction happen before or after the accrual check? Deducting leave first allows the employee to earn back accrued hours up to the cap.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Annual Carryover Cap (Year-End Reset)
&lt;/h3&gt;

&lt;p&gt;Employees can carry over up to $C$ hours into the new year. Any excess is forfeited on December 31 (or anniversary date).&lt;br&gt;
$$\text{Balance}&lt;em&gt;{\text{Jan 1}} = \min(\text{Balance}&lt;/em&gt;{\text{Dec 31}}, C)$$&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Use-It-or-Lose-It (Zero Carryover)
&lt;/h3&gt;

&lt;p&gt;All unused balance resets to 0 at year-end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mid-period pro-rating
&lt;/h2&gt;

&lt;p&gt;When an employee starts or terminates mid-pay-period, accrual should be pro-rated based on active calendar days or worked hours:&lt;/p&gt;

&lt;p&gt;$$\text{Prorated Accrual} = \text{Full Period Accrual} \times \frac{\text{Active Days in Period}}{\text{Total Days in Period}}$$&lt;/p&gt;

&lt;p&gt;Using floating-point division without rounding rules (e.g., rounding to 4 decimal places internally and 2 decimal places for display) will create a 0.0001 hour discrepancy over a full year.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation recommendations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Calculate on fixed UTC dates:&lt;/strong&gt; Store accrual transaction timestamps in UTC to avoid daylight saving time double-counting or skipping 1-hour shifts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Atomic transactions:&lt;/strong&gt; Record accruals and deductions as immutable ledger entries (&lt;code&gt;+3.33 hrs accrual&lt;/code&gt;, &lt;code&gt;-8.00 hrs usage&lt;/code&gt;) rather than mutating a single balance field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit cap evaluation order:&lt;/strong&gt; Always run &lt;code&gt;Deductions \to Accrual \to Cap Check&lt;/code&gt; in strict order during payroll runs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Testing PTO balance models
&lt;/h2&gt;

&lt;p&gt;When validating PTO accrual logic or calculating projected vacation balances for budgeting, using a dedicated calculator helps test rollover caps and period accrual schedules. The &lt;a href="https://www.miryori.org/tools/pto-calculator" rel="noopener noreferrer"&gt;PTO calculator&lt;/a&gt; at Miryori models accrual rates, carryover limits, and projected balances client-side in your browser.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: code examples illustrate HR tech calculations and are not employment law guidance.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Implementing Wind Chill in Code: 3 Boundary Bugs Around V^0.16</title>
      <dc:creator>ashley</dc:creator>
      <pubDate>Tue, 17 Nov 2026 05:22:35 +0000</pubDate>
      <link>https://www.debug.school/ashley_3a98ae2065f34c9ceb/implementing-wind-chill-in-code-3-boundary-bugs-around-v016-6b8</link>
      <guid>https://www.debug.school/ashley_3a98ae2065f34c9ceb/implementing-wind-chill-in-code-3-boundary-bugs-around-v016-6b8</guid>
      <description>&lt;p&gt;Wind-chill numbers look like temperatures, which is why most developers treat them like temperatures in unit tests and UI validations. Then an input sits slightly outside the National Weather Service domain — either too warm or too calm — and the polynomial quietly extrapolates nonsense.&lt;/p&gt;

&lt;h2&gt;
  
  
  The NWS wind chill equation
&lt;/h2&gt;

&lt;p&gt;In North America, wind chill is defined for air temperatures $T \le 50^\circ\text{F}$ ($10^\circ\text{C}$) and wind speeds $V &amp;gt; 3\ \text{mph}$ ($4.8\ \text{km/h}$):&lt;/p&gt;

&lt;p&gt;$$\text{WC} = 35.74 + 0.6215\,T - 35.75\,V^{0.16} + 0.4275\,T\,V^{0.16}$$&lt;/p&gt;

&lt;p&gt;Notice the fractional exponent $V^{0.16}$ and the interaction term $T\,V^{0.16}$. Unlike linear unit conversions, this formula is an empirical regression fitted to facial heat-loss measurements within that specific wind and temperature box.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three boundary bugs to catch in code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Computing wind chill when &lt;code&gt;V &amp;lt;= 3 mph&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;At $V = 1\ \text{mph}$, $1^{0.16} = 1$, so the formula yields $\text{WC} = 35.74 + 0.6215\,T - 35.75 + 0.4275\,T = 1.049\,T - 0.01$ — which can make $30^\circ\text{F}$ at near-calm wind report &lt;em&gt;warmer&lt;/em&gt; than air temperature ($31.46^\circ\text{F}$), violating basic physics. You must clamp: if $V \le 3\ \text{mph}$ (or $T &amp;gt; 50^\circ\text{F}$), wind chill equals the air temperature itself.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Mixing metric inputs into US customary constants
&lt;/h3&gt;

&lt;p&gt;The coefficients &lt;code&gt;35.74&lt;/code&gt;, &lt;code&gt;0.6215&lt;/code&gt;, &lt;code&gt;35.75&lt;/code&gt;, &lt;code&gt;0.4275&lt;/code&gt; only work with Fahrenheit and mph. Passing Celsius and km/h into that polynomial without converting first (or switching to the Environment Canada metric coefficients &lt;code&gt;13.12 + 0.6215*T_c - 11.37*V_kmh^0.16 + 0.3965*T_c*V_kmh^0.16&lt;/code&gt;) silently corrupts every reading. Always enforce unit tags before calling &lt;code&gt;Math.pow(v, 0.16)&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Passing negative wind speeds
&lt;/h3&gt;

&lt;p&gt;Negative &lt;code&gt;V&lt;/code&gt; turns &lt;code&gt;Math.pow(V, 0.16)&lt;/code&gt; into &lt;code&gt;NaN&lt;/code&gt; in JavaScript because a fractional power of a negative real number is undefined. Reject or clamp &lt;code&gt;V &amp;lt; 0&lt;/code&gt; at validation time.&lt;/p&gt;

&lt;h2&gt;
  
  
  A concrete check
&lt;/h2&gt;

&lt;p&gt;At $T = 20^\circ\text{F}$ and $V = 15\ \text{mph}$:&lt;br&gt;
$V^{0.16} = 15^{0.16} \approx 1.5425$, giving $\text{WC} \approx 35.74 + 12.43 - 55.14 + 13.19 = 6.2^\circ\text{F}$.&lt;/p&gt;

&lt;p&gt;If you want to verify both °F/mph and °C/km/h cases — including whether a tool properly returns raw air temperature outside the $50^\circ\text{F} / 3\ \text{mph}$ domain — Miryori's browser-side &lt;a href="https://www.miryori.org/tools/wind-chill-calculator" rel="noopener noreferrer"&gt;wind chill calculator&lt;/a&gt; exposes the active formula and unit conversion without uploading inputs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: examples above illustrate numerical formula boundaries, not emergency weather guidance.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
