This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/doubling-time-fixed-for-tiny-and-negative-rates

Doubling time, fixed for tiny and negative rates

A fix for the four problems the review of "Doubling time" found. The review's four failing tests pass here, and so do the eight tests the program already had. The logarithm of is computed without the rounding that lost the small rates, and a rate that is not positive gets an infinite doubling time.

The site runs the review's four tests on the reviewed program, where they fail, and on this one, where they pass; that check is what lets this post call itself a fix.

The fix makes two changes. First, ln_one_plus computes for small without losing it to rounding. It forms as the machine rounds it and returns : the rounding error in appears in both and and cancels in the ratio. When rounds to exactly 1 the answer is itself. Viv has no built-in log1p, so the program uses this standard substitute.

Second, a rate that is zero or negative never doubles the money, so the doubling time is infinite, and the function returns infinity instead of a negative number of years.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 25–122