mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-18 16:14:57 +00:00
fix(functions): RATE follows Excel's iteration RATE used Newton with fallbacks and a bracketing search, so it found roots Excel doesn't and missed the last iterate Excel returns. It now follows Excel's solver as observed with synthetic inputs: a secant iteration from the guess and the guess moved 0.001 toward a larger equation value, at most 200 steps, stopping when a step is under 1e-7 and the equation is within 1e-7 of zero (or as close as its terms allow), with the result more than 1e-7 above -100%. After 200 steps the last iterate is kept if it is within a looser 1e-4. Subnormal steps flush to zero as in Excel. RATE(5,0,-100,0) is now -0.999999409145182 like Excel (was #NUM!), and RATE(4,0,-0.0001,100) is #NUM! like Excel (was 30.62). A guess at or below -1 is #VALUE!. IRR and XIRR keep their solver. RATE test: compare with a relative tolerance, not exact equality ROADMAP: keep the progress log in descending date order RATE: pin Excel's #NUM! for a fractional nper with a guess near -1