title: PostgreSQL Math Function Error
body: <p>I'm getting an error from a deterministic PG function that seems dependent based on when I call it in a query.</p>
  
  <p>The function is:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION ircm(starting_money numeric, value numeric, days numeric)
  RETURNS numeric
  AS $$
  BEGIN
  -- Calculate effective interest rate, compounded monthly.
      RETURN 12*(pow((value/starting_money),(1./(12.*(days/365.)))) - 1);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>If I call it in a simple SELECT statement, it works fine:</p>
  
  <pre><code>SELECT ircm(100.00,60.427500643787215,30)
  Result: -4.79925436505569765596
  </code></pre>
  
  <p>However, when I run that exact same call from a different SELECT statement using a subquery:</p>
  
  <pre><code>SELECT
      ircm(100.00,m.v::numeric,30) AS result
  FROM(
      SELECT 60.427500643787215 AS v
  ) m
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>ERROR:  a negative number raised to a non-integer power yields a complex result
  CONTEXT:  PL/pgSQL function "ircm" line 6 at RETURN
  </code></pre>
  
  <p>Since the calls are logically equivalent, how can PG be returning an error for one call, but not the other? I've made sure there's only one definition of the function "ircm" in my database. I've tried dropping/adding it again to make sure PG isn't somehow caching a corrupted definition. </p>