C.   Mathematical and Numerical Reference

This appendix defines the mathematics used by the current calculator and the numerical conventions that affect its results. The operating instructions and key sequences are in chapter 7, chapter 8, chapter 10, chapter 11, chapter 12, chapter 13 and chapter 9. A formula here specifies the intended calculation; its individual operations still take place at finite working precision. Algebraically equivalent formulas need not produce identical last digits.

Unless a section says otherwise, the formulas below assume finite real arguments; individual commands may reject nonfinite inputs or propagate a nonfinite result. For a two-operand scientific command in RPN, \(y\) denotes the older operand in Y, displayed at S1, and \(x\) the newer operand in X, displayed at S0. Last X and Last Y are separately saved operands, not these current positions. In ALG, the corresponding operands are the left and right arguments; ALG has no S0/S1 stack positions. Other mathematical symbols name the quantities defined in their sections, with register or worksheet mappings given in the operating chapters. Both modes use the scientific, statistical, financial, and conversion mathematics described here. RPN supplies operands from the stack; ALG uses its expression and labeled worksheets. Their operating sequences and result placement are documented in chapter 15.

C.1   Finite multiple precision

Decimal settings and binary storage

SpicyRPN uses MPFR numbers with a binary significand. A requested working precision of \(d\) decimal digits selects

\[ p=\left \lceil d\log _2 10\right \rceil \]

binary significand bits. For example, 16, 600, and 10,000 decimal digits select 54, 1,994, and 33,220 bits. The default is 600 decimal digits; the settings interface accepts 16 through 10,000. Exponents have a separate, finite range. Increasing significand precision does not make the exponent range unlimited.

A finite decimal fraction is exact in binary only when its reduced denominator is a power of two and its significand fits. Thus a catalog factor such as \(0.3048\) can be an exact decimal definition while its stored binary value is rounded. Signed zero, infinities, and a not-a-number result are also represented. A mathematical domain error may therefore appear as a nonfinite result, or a command may reject its inputs before evaluating the underlying function.

Precision propagation

Each stored real value retains the precision at which it was created. Changing the setting does not rewrite the stack, memories, or financial and statistical registers. Subsequent calculations create results at the current working precision, using the available bits of their operands. Raising precision cannot recover digits already lost when a value was entered or computed. A complex pair contains two such real components, which can have different creation precisions. See section 5.7.

The usual directly evaluated MPFR arithmetic and elementary functions use round-to-nearest, with an exact halfway case resolved toward an even final binary significand bit. MPFR treats the stored input values as exact when rounding one operation. This is a guarantee about that operation on those inputs, not about a sequence of operations, uncertain measurements, or a SpicyRPN iterative algorithm. MPFR’s definitions are given in its manual, https://www.mpfr.org/mpfr-4.2.2/mpfr.html#Rounding.

Displayed digits and reliable digits

FIX, SCI, and ENG select formatting; they do not increase the information in a value. Display rounding uses nearest with ties to even. FIX may switch to scientific notation when fixed notation cannot usefully show the result, including a nonzero value that would otherwise display as zero. The permitted display setting is zero through the current working digit count. The meanings of the digit setting and the notation fallback are explained in section 5.3.

Cancellation, ill conditioning, repeated rounding, and numerical root finding can reduce the number of trustworthy digits. A display containing hundreds of digits is not an error bound. Repeating a calculation with freshly entered inputs at a higher precision is a useful check; agreement alone is not a proof of accuracy or uniqueness.

C.2   Rounding and integer conventions

For a real \(x\), \(\operatorname {trunc}(x)\) removes its fractional part toward zero, \(\lfloor x\rfloor \) rounds down, and \(\lceil x\rceil \) rounds up. The fractional-part function is

\[ \operatorname {frac}(x)=x-\operatorname {trunc}(x). \]

It is negative for a negative noninteger input. NINT rounds to the nearest integer with ties to even: both \(1.5\) and \(2.5\) round to 2.

The financial RND command instead rounds the value to \(k\) decimal places, where \(k\) is the display digit setting. Its mathematical rule is

\begin{equation} \operatorname {RND}_k(x)= \operatorname {sgn}(x)\, \frac {\left \lfloor |x|10^k+\tfrac 12\right \rfloor }{10^k}. \label {eq:math-rnd} \end{equation}

An exact halfway decimal case rounds away from zero. The scaling and rounding operations themselves use finite precision. RND uses decimal places even when SCI or ENG is selected; it changes the stored result. See section 5.6.

The two real remainder conventions differ in their quotient:

\begin{align*} \operatorname {mod}(y,x)&=y-\operatorname {trunc}(y/x)x,\\ \operatorname {rem}(y,x)&=y-\operatorname {nint}(y/x)x. \end{align*}

For REM, the quotient is chosen by nearest-integer, ties-to-even rounding; these are definitions of the remainder operation, not instructions to round a displayed quotient first. The divisor must be nonzero. MOD consequently has the dividend’s sign when its result is nonzero. It is not the always nonnegative modulo convention used by some programming languages.

C.3   Real scientific definitions and domains

Arithmetic, powers, and logarithms

The basic binary operations are \(y+x\), \(y-x\), \(yx\), and \(y/x\). Negation means \(-x\), absolute value means \(|x|\), reciprocal means \(1/x\), square means \(x^2\), and the real square root is the nonnegative root, defined for \(x\geq 0\). The real power is \(y^x\). A negative base requires an integer exponent for this real power command. A zero base with a negative exponent is not a finite result; the power implementation returns 1 for \(0^0\).

For the root command, \(y\) is the radicand and \(x\) the index. An integer index must be nonzero and lie between \(-1{,}000{,}000\) and \(1{,}000{,}000\). An odd integer index permits a negative radicand; an even one does not. A negative index takes the reciprocal of the corresponding positive-index root. A noninteger index uses \(y^{1/x}\) and requires a nonnegative real radicand. These real rules differ from the complex root convention in section C.4.

The exponential functions are \(e^x\) and \(10^x\). Natural and common logarithms are \(\ln x\) and \(\log _{10}x=\ln x/\ln 10\); the binary logarithm is \(\log _2x=\ln x/\ln 2\). They require positive real input for a finite result. The two-argument logarithm is

\[ \log _y x=\frac {\ln x}{\ln y},\qquad x>0,\quad y>0,\quad y\ne 1. \]

The constants \(\pi \), \(e=\exp (1)\), and \(\ln 2\) are computed at the current working precision; they are not stored short decimal approximations.

The percentage functions use these operand orders:

\[ \%:\ \frac {yx}{100},\qquad \%\text { change}:\ \frac {100(x-y)}{y},\qquad \%\text { total}:\ \frac {100x}{y}. \]

The latter two require \(y\ne 0\). In RPN, their stack behavior preserves the base in Y; ALG treats them as binary functions of the left and right operands. See chapter 3 and chapter 15.

Angles and hyperbolic functions

Let the conversion from the selected angle unit to radians be

\[ s=\begin {cases} \pi /180&\text {DEG},\\ 1&\text {RAD},\\ \pi /200&\text {GRAD}. \end {cases} \]

Circular functions evaluate \(\sin (sx)\), \(\cos (sx)\), and \(\tan (sx)\). Their inverse results are the principal radian values divided by \(s\). The real implementation uses MPFR’s angle-unit operations where available, so the displayed formula does not imply a preliminary rounded multiplication by a stored value of \(s\).

Table C.1: Real inverse functions: domains and principal ranges in radians.
Function Input domain Principal range
\(\arcsin x\) \([-1,1]\) \([-\pi /2,\pi /2]\)
\(\arccos x\) \([-1,1]\) \([0,\pi ]\)
\(\arctan x\) All finite real \(x\) \((-\pi /2,\pi /2)\)
\(\operatorname {asinh}x\) All finite real \(x\) All real values
\(\operatorname {acosh}x\) \([1,\infty )\) \([0,\infty )\)
\(\operatorname {atanh}x\) \((-1,1)\) All real values

The two-argument angle function uses \(\operatorname {atan2}(y,x)\), with quadrant determined from both arguments, and returns the result in the selected angle unit. Its signed-zero cases follow the underlying real operation. The polar interpretation of complex numbers is described in chapter 8.

Hyperbolic functions do not use the angle setting:

\[ \sinh x=\frac {e^x-e^{-x}}2,\qquad \cosh x=\frac {e^x+e^{-x}}2,\qquad \tanh x=\frac {\sinh x}{\cosh x}. \]

These identities define the functions; the implementation calls the numerical library rather than necessarily evaluating the displayed differences.

Factorials, combinatorics, and special functions

The ordinary factorial and permutation/combination commands accept integers:

\begin{align*} n!&=\prod _{j=1}^{n}j,\qquad 0!=1,\\ {}_nP_k&=\frac {n!}{(n-k)!},\\ {}_nC_k&=\frac {n!}{k!(n-k)!}. \end{align*}

The bounds are \(0\leq n\leq 10{,}000\) and \(0\leq k\leq n\). Combinations use the smaller of \(k\) and \(n-k\), with interleaved multiplication and division. The result is mathematically an integer, but it is stored at finite precision and need not retain every integer digit.

For positive real \(x\),

\[ \Gamma (x)=\int _0^\infty t^{x-1}e^{-t}\,dt, \qquad \Gamma (x+1)=x\Gamma (x). \]

Continuation defines the function elsewhere except its poles at zero and negative integers. The real logarithmic gamma function is the real \(\ln \Gamma (x)\) where defined; it is not a request for \(\ln |\Gamma (x)|\) on intervals where gamma is negative. The logarithmic factorial computes \(\ln \Gamma (n+1)\) for a finite nonnegative integer \(n\); it does not impose the ordinary factorial’s 10,000 bound.

The error functions are

\[ \operatorname {erf}(x)=\frac 2{\sqrt \pi }\int _0^x e^{-t^2}\,dt, \qquad \operatorname {erfc}(x)=1-\operatorname {erf}(x). \]

For real arguments, ERFC is evaluated directly by the library, avoiding the loss that a separate subtraction from 1 can cause in a small tail. Complex implementations and their limits are described below.

The random-number command constructs a uniformly sampled decimal digit string at the requested working digit count and converts it to a stored number. A conversion that rounds to 1 is retried, so the stored result lies in \([0,1)\). There is no user seed control. This is finite random sampling, not a supply of arbitrary exact real numbers.

C.4   Complex principal values

Write \(z=a+ib\). MPC provides complex addition, subtraction, multiplication, division, negation, reciprocal, magnitude, powers, square root, exponentials, logarithms, and circular/hyperbolic functions and their inverses. The C bridge transfers the stored MPFR components directly, without converting them through machine floating point or decimal text. Scalar coefficients and valid real-function paths use MPFR. RPN and ALG share this numerical implementation.

For a single MPC primitive, the real and imaginary results are correctly rounded independently to nearest, ties to even, at the precision of that call. Direct elementary operations request the selected working precision. This guarantee concerns the operation on its stored inputs, not the accuracy of those inputs or an entire composed calculation. See the MPC reference manual for the upstream definitions.

For polar magnitude \(\rho \) and displayed phase \(\theta \), the rectangular components are

\[ a=\rho \cos (s\theta ),\qquad b=\rho \sin (s\theta ), \]

where \(s\) is the selected angle-unit scale from section C.3. In the reverse direction, \(\rho =|z|\) and \(\theta =\operatorname {atan2}(b,a)/s\), with the two-argument angle interpreted in radians before that scaling. The displayed phase of zero is set to zero. These representation changes do not redefine the logarithm branch below.

Composed indexed roots, arbitrary-base logarithms, and percentages use 20 additional decimal guard digits and round the final components back to the requested working precision. Angle-unit conversions and custom special functions also use additional intermediate precision as needed by their algorithms. A zero-imaginary input can use a real-library result when that result is not not-a-number. Consequently, a scalar special case may use a different numerical path from a nearby genuinely complex value. Guard digits reduce intermediate rounding; they do not guarantee correctly rounded final results for compositions, conversions, or approximations.

Logarithms, square roots, powers, and roots

The principal logarithm is

\begin{equation} \operatorname {Log}z=\ln |z|+i\operatorname {Arg}z, \qquad -\pi <\operatorname {Arg}z\leq \pi . \label {eq:math-complex-log} \end{equation}

The negative real axis is taken on its upper side: for \(r>0\), \(\operatorname {Log}(-r)=\ln r+i\pi \). A negative zero in the imaginary component does not choose the lower side of that axis. The imaginary part of a logarithm remains in radians in every angle mode.

The principal square root has nonnegative real part and, on the negative real axis, positive imaginary part:

\[ \sqrt {-r}=i\sqrt r\quad (r>0). \]

In the general case it is the principal value associated with \(\exp (\tfrac 12\operatorname {Log}z)\); MPC evaluates square root directly.

The common and binary logarithms equal \(\operatorname {Log}z/\ln 10\) and \(\operatorname {Log}z/\ln 2\); MPC evaluates each directly. A logarithm of argument \(z\) to complex base \(w\) divides \(\operatorname {Log}z\) by \(\operatorname {Log}w\). Zeros of a denominator remain singular cases; complex mode does not supply a separate multivalued logarithm selection.

General complex powers and roots follow

\[ z^w=\exp \!\left (w\operatorname {Log}z\right ),\qquad \sqrt [w]{z}=z^{1/w},\quad w\ne 0. \]

The power command uses MPC’s power function directly, and the integer-power operation uses its integer-exponent primitive. The displayed identities define branch choices rather than a mandatory evaluation sequence. The implementation returns 1 for \(0^0\) and zero for zero raised to a positive real power. Other zero-base cases must be judged by their singularity rather than by the logarithm identity alone.

The complex root is one principal value, not a list of all roots. Thus the principal complex cube root of \(-8\) is \(1+i\sqrt 3\), whereas the real odd-root command gives \(-2\) in real mode. See table 8.4 for representative branch-boundary values.

Circular and inverse functions

The complex exponential and circular functions satisfy

\begin{align*} e^{a+ib}&=e^a(\cos b+i\sin b),\\ \sin (a+ib)&=\sin a\cosh b+i\cos a\sinh b,\\ \cos (a+ib)&=\cos a\cosh b-i\sin a\sinh b,\\ \tan z&=\sin z/\cos z. \end{align*}

These are mathematical identities; MPC evaluates the functions directly, including tangent without a separate rounded sine/cosine quotient. Circular input is scaled to radians in both components according to the angle setting. Both components of an inverse circular result are scaled back to the selected angle unit. Hyperbolic functions and their inverses are not angle-scaled.

The principal inverse functions satisfy the following identities away from their singularities, with the exact-axis choices in table 8.4:

\begin{align*} \arcsin z&=-i\operatorname {Log}\!\left (iz+\sqrt {1-z^2}\right ),\\ \arccos z&=\frac \pi 2-\arcsin z,\\ \arctan z&=\frac i2\left [ \operatorname {Log}(1-iz)-\operatorname {Log}(1+iz)\right ],\\ \operatorname {acosh}z&=\operatorname {Log}\!\left ( z+\sqrt {z+1}\sqrt {z-1}\right ),\\ \operatorname {atanh}z&=\frac 12\left [ \operatorname {Log}(1+z)-\operatorname {Log}(1-z)\right ]. \end{align*}

For inverse hyperbolic sine, define \(H(z)=\operatorname {Log}(z+\sqrt {z^2+1})\). The branch selection follows \(H(z)\) when \(\Re z\geq 0\), and \(-H(-z)\) when \(\Re z<0\). All logarithms and square roots in these identities use the principal conventions above. MPC evaluates the six inverse functions directly, instead of forming these logarithmic differences or differences from \(\pi /2\). The bridge deliberately chooses signed zeros on the axes to preserve SpicyRPN’s documented branch values. Singularities and branch cuts remain part of the result; see section 8.9.

Complex gamma and error functions

MPC does not provide the following special functions. SpicyRPN’s algorithms use MPC for complex intermediate arithmetic and elementary functions, with MPFR for real coefficients. Correctly rounded primitives do not certify the accuracy of a complete approximation or series.

Complex gamma uses a finite Spouge approximation, with the reflection identity

\[ \Gamma (z)=\frac \pi {\sin (\pi z)\Gamma (1-z)} \]

when \(\Re z<\tfrac 12\). At requested precision \(d\), the coefficient count is \(\lfloor 3d/2\rfloor +24\), and the calculation uses roughly \(2d+50\) decimal working digits before rounding back. The supported request is at most 10,000 digits. These choices are numerical safeguards rather than a certificate that every returned digit is correct, especially near poles. For a genuinely complex argument, logarithmic gamma is the principal logarithm of the computed gamma value, not a continuously unwrapped log-gamma branch. Complex factorial continues the real factorial as \(z!=\Gamma (z+1)\), and complex logarithmic factorial uses \(\operatorname {Log}\Gamma (z+1)\). These continuations also apply to real inputs for which the ordinary real factorial path is rejected; they are not restricted to nonnegative integers in complex mode. Poles remain excluded. A valid real fast path retains the real convention described above.

The complex error function uses the series

\[ \operatorname {erf}(z)=\frac 2{\sqrt \pi } \sum _{j=0}^{\infty }\frac {(-1)^j z^{2j+1}}{j!(2j+1)}. \]

It applies a magnitude limit of approximately \(|z|\leq 100\), additional precision depending on \(|z|^2\), and a finite term budget and relative-term stopping test. The preliminary magnitude check uses a coarse conversion to a machine number, so it is not an exact boundary test at radius 100. Failure to converge is reported rather than extending the series indefinitely. Complex ERFC is computed as \(1-\operatorname {erf}(z)\), so small complex tails can suffer cancellation. This differs from real ERFC’s direct path.

Integer rounding, real remainders, the two-argument real angle, permutations, combinations, RND, statistics, financial functions, and unit conversions remain real operations. Turning complex mode off preserves existing stored imaginary components, but new calculations, memory writes, recalls, and register assignments use only the real component and write zero imaginary part. A recall does not change its source memory. Associative keys always use only the real component, regardless of CMPLX; equal real keys identify one entry. See section 8.7, section 6.5 and section 6.7. Complex mode does not turn every operation into a complex analytic continuation.

C.5   Statistical accumulators and results

The statistical bank stores a count \(n\) and five sums, not individual observations:

\[ n,\quad \sum x,\quad \sum x^2,\quad \sum y,\quad \sum y^2,\quad \sum xy. \]

Each sum runs over the entered observation pairs. Here \(x,y\) are data coordinates, not names of stored stack positions; \(n\) is independent of the financial n register. The input and result placement in chapter 10 supplies the RPN or ALG mapping. Adding a pair adds \((1,x,x^2,y,y^2,xy)\); removing it subtracts the same quantities. A removal is blocked when it would make the count negative, but there is no sample list with which to establish that the pair was ever entered. Statistical quantities can therefore become inconsistent after an incorrect removal. Addition and removal require finite real components of both sample coordinates and finite existing and proposed values for all six totals. NaN, infinity, or overflow to a nonfinite total rejects the entire update without changing the bank. Imaginary components are not statistical inputs. These checks do not eliminate cancellation or validate the sample history. The R4–R9 transfer copies accumulators into ordinary memory; it is not a second sample bank or a reverse import mechanism.

The ordinary means and weighted mean are

\[ \bar x=\frac {\sum x}{n},\qquad \bar y=\frac {\sum y}{n},\qquad \bar x_w=\frac {\sum xy}{\sum y}. \]

The ordinary means require \(n>0\). The weighted mean additionally requires \(\sum y\ne 0\) and treats each \(y_j\) as a weight. In the other operations, \(y\) remains the second measured variable; the bank is not globally switched into a weighted-statistics mode.

Define the centered, count-scaled sums using the same \(M,N,P\) notation as section 10.7:

\begin{equation} \begin {aligned} M&=n\sum x^2-(\sum x)^2,\\ N&=n\sum y^2-(\sum y)^2,\\ P&=n\sum xy-(\sum x)(\sum y). \end {aligned} \label {eq:math-stat-moments} \end{equation}

Sample standard deviations are

\[ s_x=\sqrt {\frac {M}{n(n-1)}},\qquad s_y=\sqrt {\frac {N}{n(n-1)}},\qquad n>1. \]

They use the sample divisor \(n-1\), not the population divisor \(n\). A negative variance numerator is invalid, even when it arose from rounding rather than from the intended data.

For the least-squares line \(\hat y=a+bx\),

\[ b=\frac PM,\qquad a=\frac {M\sum y-P\sum x}{nM}. \]

The fit requires \(n>1\) and \(M>0\). A constant \(y\) is permissible for the fitted line, but not for a correlation coefficient. The estimate and correlation command uses

\begin{equation} \hat y(x_0)=\frac {(nx_0-\sum x)P+M\sum y}{nM},\qquad r=\frac P{\sqrt {MN}}. \label {eq:math-stat-estimate} \end{equation}

That command requires \(n>1\), \(M>0\), and \(N>0\), because it returns both the estimate and correlation. Its estimate is evaluated by dividing the numerator by \(n\), then by \(M\). The correlation is not clamped to \([-1,1]\) after calculation.

These are raw-sum formulas. When observations have a large common offset and a very small spread, the subtractions defining \(M,N,P\) can lose many digits. Higher precision or a carefully chosen change of origin can help. Operational examples and the order of returned results are in chapter 10.

C.6   Time value of money

Common equation and sign convention

Let \(n\) be the number of periods, \(r=i/100\) the interest rate per period, \(q=1+r\), and \(b=0\) for END or \(b=1\) for BEGIN. Money paid and money received must have opposite signs from one consistent viewpoint. Define

\[ A_f=\begin {cases}q^b(q^n-1)/r&r\ne 0,\\n&r=0,\end {cases} \qquad A_p=A_fq^{-n}. \]

The calculator solves the equation

\begin{equation} \mathrm {PV}\,q^n+\mathrm {PMT}\,A_f+\mathrm {FV}=0. \label {eq:math-tvm} \end{equation}

All four nontarget registers participate; an unwritten register supplies zero. The interest domain is \(r>-1\), equivalent to \(i>-100\). The supplied period count must be nonnegative, and solving PMT or interest requires a positive period count. All supplied values must be finite.

These are the same shared registers in both entry modes. In RPN, the financial key either stores or solves according to the entry state. In ALG, the register key stores the displayed operand, and CPT followed by the register key solves it. ALG’s other financial worksheets use their accepted named inputs, initialized from the corresponding registers or worksheet defaults. Accepting a linked field with ENTER writes that financial register; COMPUTE applies the calculation’s stated updates. See chapter 11 for the full input and result conventions.

The direct solutions are

\begin{align*} \mathrm {PV}&=-\left (\mathrm {FV}\,q^{-n}+\mathrm {PMT}\,A_p\right ),\\ \mathrm {FV}&=-\left (\mathrm {PV}\,q^n+\mathrm {PMT}\,A_f\right ),\\ \mathrm {PMT}&=-\frac {\mathrm {PV}+\mathrm {FV}\,q^{-n}}{A_p}. \end{align*}

At zero interest these reduce to \(\mathrm {PV}+n\mathrm {PMT}+\mathrm {FV}=0\). A manually supplied fractional \(n\) is used in these compound-growth formulas. It does not activate an HP odd-first-period interest convention.

For improved behavior near zero interest, let \(t=\ln (1+r)\). For nonzero \(t\), the annuity factors are evaluated using

\begin{align*} H&=\frac {\sinh (nt/2)}{\sinh (t/2)},\\ A_f&=H\exp \!\left (\frac {n-1}{2}t+bt\right ),\\ A_p&=H\exp \!\left (-\frac {n+1}{2}t+bt\right ). \end{align*}

A small-argument logarithm uses \(\ln (1+x)=2\operatorname {atanh}(x/(2+x))\) for \(|x|<1/2\). These evaluation choices matter when \(r\) is tiny relative to the working precision.

Solving and rounding the number of periods

At \(r=0\), the unrounded solution is

\[ n_*=-\frac {\mathrm {PV}+\mathrm {FV}}{\mathrm {PMT}}. \]

If PMT is zero, a zero numerator makes the equation indeterminate; otherwise there is no solution. For nonzero interest, define

\[ D=r\mathrm {PV}+\mathrm {PMT}\,q^b,\qquad \delta =-\frac {r(\mathrm {PV}+\mathrm {FV})}{D}. \]

When \(D\ne 0\) and \(1+\delta >0\),

\[ n_*=\frac {\ln (1+\delta )}{\ln (1+r)}. \]

A zero \(D\) is checked for an indeterminate or impossible equation. A negative or nonfinite \(n_*\) is rejected.

A solved \(n\) is then rounded with the financial period rule, rather than ordinary nearest-integer rounding. Let \(h=\lfloor n_*\rfloor \), \(f=n_*-h\), and let \(d\) be the working decimal precision. Define

\[ \epsilon =\min \!\left ( 10^{-\max (1,d-2)}\max (1,n_*),\;10^{-12}\right ). \]

If \(f<0.005-\epsilon \), the stored result is \(h\); otherwise it is \(h+1\). The small guard makes a numerically computed threshold case round up. This rule applies to solving \(n\), not to a fractional value manually stored in n.

Solving interest and interpreting the period

With PMT zero, the rate solution follows

\[ t=\frac {\ln (-\mathrm {FV}/\mathrm {PV})}{n}, \]

requiring opposite, nonzero PV and FV. When \(n=1\), a nonzero payment also permits a direct solution:

\[ q=\begin {cases} -(\mathrm {FV}+\mathrm {PMT})/\mathrm {PV}&\text {END},\\ -\mathrm {FV}/(\mathrm {PV}+\mathrm {PMT})&\text {BEGIN}. \end {cases} \]

A zero denominator is classified as indeterminate or impossible, and a permissible solution requires \(q>0\). Other cases use numerical root finding in \(t=\ln q\), starting at zero; see section C.9. The final periodic percentage is evaluated as

\[ i=200e^{t/2}\sinh (t/2), \]

which is mathematically \(100(e^t-1)\).

A period is the common unit of \(n\), \(i\), and PMT. The annual-rate shortcut divides a nominal annual percentage by 12; the years shortcut multiplies a year count by 12. Neither converts an effective annual rate. For an effective annual fraction \(j\) and \(m\) equal periods per year, the equivalent periodic fraction would be \((1+j)^{1/m}-1\). See chapter 11 for complete setups and cash-sign examples.

C.7   Amortization and simple interest

Amortization recurrence

Let \(B_0=\mathrm {PV}\), \(P=\mathrm {PMT}\), \(r=i/100\), and let \(n_0\) be the stored count of elapsed payments. For a requested block of \(k\) payments, the recurrence is

\begin{align*} I_j&=\begin {cases} 0&\text {BEGIN and }n_0+j-1=0,\\ -rB_{j-1}&\text {otherwise}, \end {cases}\\ D_j&=P-I_j,\\ B_j&=B_{j-1}+D_j,\qquad j=1,\ldots ,k. \end{align*}

Here \(I_j\) and \(D_j\) are signed interest and principal portions from the same viewpoint as the payment. AMORT returns their block totals, updates PV to \(B_k\), and updates \(n\) to \(n_0+k\). FV does not participate. See section 11.11 for result placement.

The input PV and PMT must be nonzero and opposite in sign; \(i\) must exceed \(-100\); \(n\) must be a nonnegative integer. In RPN, all four registers must actually be present, rather than merely supplying unwritten zeros. ALG validates the corresponding accepted worksheet inputs. The block count is an integer from zero through 100,000. A zero block still validates the financial setup. There is no automatic stop at an original loan term or at payoff, and no per-payment currency rounding. Consequently, this recurrence need not reproduce a lender’s statement that rounds every posting to cents.

Simple interest

For simple interest, let \(P=-\mathrm {PV}\), \(d=n\) be the day count, and \(j=i/100\) be the annual rate fraction. The returned interest amounts are

\[ I_{360}=Pj\frac d{360},\qquad I_{365}=Pj\frac d{365}. \]

The principal \(P\) is also returned as a separate result. All three inputs must be finite; RPN additionally requires the three registers to have been stored. The day count \(d\geq 0\) may be fractional. This command permits any finite annual rate, including values outside the TVM rate domain. BEGIN/END and PMT/FV do not enter the formulas. See section 13.2.

C.8   Cash-flow discounting and internal rate of return

For the selected cash-flow prefix \(C_0,C_1,\ldots ,C_N\),

\begin{equation} \operatorname {NPV}(i)=\sum _{j=0}^{N}\frac {C_j}{(1+i/100)^j}. \label {eq:math-npv} \end{equation}

Each position is one equally spaced period; position zero is now. The n input is the final included index, not a count of payments or a frequency. It must be an integer from 0 through 999 within the available cash-flow list. NPV requires finite \(i>-100\). RPN reads explicitly stored n and i; ALG uses the corresponding accepted worksheet inputs. The computation uses reverse Horner evaluation: start with zero, then successively replace \(V\) by \(C_j+V/q\), from the last selected flow back to the first, where \(q=1+i/100\).

IRR finds a rate for which \(\operatorname {NPV}(i)=0\). At least two selected flows are required, with both positive and negative values. An all-zero stream is indeterminate. The selected prefix is normalized by its largest absolute amount; zero flows at its ends can be removed for the search without changing any finite root. In the transformed variable \(t=\ln (1+i/100)\), the residual is evaluated with decay factors \(e^{-|t|}\) and a direction chosen to avoid unnecessary exponential growth. This rescales the equation without changing its finite zeros.

Without explicit bounds, RPN uses a stored valid \(i\) as the guess, or zero when it is unwritten; ALG uses its accepted initial-guess field. Optional bounds must be ordered, exceed \(-100\), and either contain a sign change or give a computed zero at an endpoint. A stream with several sign changes can have several IRRs; the root found depends on the guess and bracket. An even-multiplicity root may not produce a sign change at all. A failed bracket search is not a proof that no mathematical root exists. The controls are in section 12.8; numerical stopping is described in section C.9.

NPV does not store PV, and IRR does not store i. BEGIN/END has no effect on these equally spaced cash-flow positions. The bank holds at most 1,000 expanded flows including \(C_0\). A repetition count \(f\) from 1 through 1,000 appends \(f-1\) additional copies at the actual end of the list, subject to remaining capacity. Repetition is expansion, not a compressed weighting in equation (C.6).

C.9   Financial numerical root finding

TVM interest, IRR, and multi-coupon bond yield use bracketed numerical searches. Rates are transformed to \(t=\ln (1+r)\), which automatically keeps \(r>-1\). For a search without supplied bounds, the first bracket step is 0.01 in \(t\); the step doubles during expansion, testing the lower side first. TVM begins at \(t=0\), IRR uses its rate guess, and the bond yield calculation starts from a 3.5 percent semiannual rate, equivalent to 7 percent nominal annual yield.

Within a valid bracket, the solver alternates midpoint and secant candidates, using only candidates inside the bracket. Its standard width criterion is

\begin{equation} |b-a|\leq 10^{-30}\max (1,|a|,|b|), \label {eq:math-solver-stop} \end{equation}

where \(a,b\) are bounds in \(t\), not percentages. A computed zero residual also stops the search, as does a candidate indistinguishable from an endpoint at the available precision. There are 200 iterations per search stage and a 100,000-evaluation budget. These settings are not user controls.

The tolerance is not a promise of 30 correct decimal places in the displayed rate. Transforming back to a periodic percentage multiplies small errors in \(t\) by approximately \(100e^t\); the bond’s nominal annual percentage has a factor \(200e^t\). Finite-precision residuals, cancellation, conditioning, multiple roots, and the precision of the input values also matter. A computed zero is a zero of the evaluated residual, not a proof that the exact residual vanishes. Increasing working precision improves arithmetic but does not change this fixed search tolerance.

C.10   Gregorian dates and day counts

Encoding and validation

The accepted calendar is proleptic Gregorian, with years 1 through 9999. A leap year is divisible by 4 except that a year divisible by 100 must also be divisible by 400. Numeric date encodings are

\[ \text {MDY}:\ M+\frac D{100}+\frac Y{10^6},\qquad \text {DMY}:\ D+\frac M{100}+\frac Y{10^6}. \]

Thus the final four decimal places are the four-digit year. Display rounding does not add or remove stored date fields.

The decoder scales by \(10^6\) using at least 64 bits and at least the current and input precisions, rounds to an integer, validates the calendar fields, then re-encodes the date at the input precision. It requires equality with that canonical encoding. Extra nonzero date digits are therefore not silently treated as a fractional day. See section 13.3 for safe date entry.

Actual days and the implemented 30/360 rule

Let \(Y'=Y-1\). An ordinal with 1 January of year 1 equal to zero is

\[ O(Y,M,D)=365Y'+\left \lfloor \frac {Y'}4\right \rfloor -\left \lfloor \frac {Y'}{100}\right \rfloor +\left \lfloor \frac {Y'}{400}\right \rfloor +\sum _{m=1}^{M-1}\operatorname {days}(Y,m)+D-1. \]

Actual days from date 1 to date 2 are \(O_2-O_1\): the calculation is an elapsed interval, not an inclusive count of both endpoints. Date addition requires an integer offset between \(-3{,}652{,}058\) and \(3{,}652{,}058\), and the resulting date must remain in years 1–9999.

For the second day-count result, form

\[ d_1=\begin {cases}30&D_1=31\text { and }D_2\geq 30,\\D_1&\text {otherwise},\end {cases} \qquad d_2=\min (D_2,30). \]

Then the implemented 30/360 count is

\begin{equation} 360(Y_2-Y_1)+30(M_2-M_1)+d_2-d_1. \label {eq:math-days360} \end{equation}

There is no special February-end adjustment. This exact rule matters: it gives 27 from 31 January to 28 February in the same year, but \(-28\) in the reverse direction. Do not assume antisymmetry or substitute a different market convention merely because both are called 30/360.

C.11   Semiannual bonds

The bond functions model redemption at 100, a nonnegative annual coupon percentage stored in PMT, and semiannual coupon payments. Put

\[ C=\mathrm {PMT}/2,\qquad r=i/200,\qquad q=1+r. \]

Prices and coupon amounts are per 100 of redemption value. Settlement must precede maturity. Coupon dates are obtained by moving backward in six-month steps from maturity. A maturity on a month’s last day preserves month-end; otherwise a date uses the maturity’s day number, clipped when necessary to the target month’s last day. A preceding coupon date must exist within the supported calendar. See section 13.6.

Let \(N\) be the number of coupons strictly after settlement. Let \(E\) be the actual days in the coupon period containing settlement, and \(d\) the actual days from settlement to its next coupon. Define

\[ w=d/E,\qquad 0<w\leq 1,\qquad A=C(1-w), \]

where \(A\) is accrued interest. Settlement on a coupon date excludes that day’s coupon, uses the following coupon as the next one, and gives \(w=1\), \(A=0\).

With at least two remaining coupons, the dirty price and clean price are

\begin{equation} P_{\mathrm {dirty}}= \sum _{j=0}^{N-1}\frac C{q^{w+j}} +\frac {100}{q^{w+N-1}},\qquad P_{\mathrm {clean}}=P_{\mathrm {dirty}}-A. \label {eq:math-bond-price} \end{equation}

The implementation evaluates the coupon series in a stable nested form and uses logarithmic growth for the fractional exponent. With only one remaining coupon, it uses simple interest over the remaining fraction of a period:

\begin{equation} P_{\mathrm {dirty}}=\frac {100+C}{1+rw},\qquad P_{\mathrm {clean}}=P_{\mathrm {dirty}}-A. \label {eq:math-bond-last} \end{equation}

This final-period formula is deliberately different from substituting \(N=1\) into the compound formula.

Price requires a finite yield with \(i>-200\), corresponding to \(r>-1\), and a finite nonnegative coupon. Yield requires a finite positive clean price in PV and a finite nonnegative coupon. RPN requires these financial registers to have been stored; ALG uses the accepted worksheet inputs. For one remaining coupon, its direct nominal annual percentage is

\[ i=\frac {200}{w}\left (\frac {100+C}{\mathrm {PV}+A}-1\right ), \]

subject to the same rate domain. For several coupons, numerical root finding solves the clean-price equation; section C.9 describes the search.

PRC stores the calculated clean price in PV; YTM stores the nominal annual yield percentage in i. The stored n, FV, and BEGIN/END do not participate. These functions do not model odd coupon periods, a call date, alternative redemption amounts, or another coupon frequency. See section 13.7.

C.12   Depreciation methods

Let \(K=\mathrm {PV}\) be cost, \(S=\mathrm {FV}\) salvage value, \(L=n\) life in years, and \(B=K-S\) the depreciable basis. Inputs require finite values with \(K\geq S\geq 0\), \(L>0\), and a requested integer year \(j\geq 1\). PMT does not participate. Each method returns the depreciation for year \(j\) and the depreciable amount remaining after that year, excluding salvage. RPN requires the input registers to have been stored; ALG uses its accepted worksheet inputs. The depreciation calculation itself does not rewrite the financial input registers.

Set \(m=\lceil L\rceil \). A requested year beyond \(m\), or a zero basis, gives zero for both results. For the declining-balance methods, the factor is still validated before that shortcut. Fractional lives are accepted, with the last active year handled as specified below; no automatic currency rounding is performed.

Straight line

The fraction of a full year still available in year \(j\) is \(u_j=\min (1,L-j+1)\). Within the active life,

\[ D_j=\frac BL u_j,\qquad R_j=\max \!\left (0,B-\frac BL\min (j,L)\right ). \]

Thus a final fractional year receives the corresponding fraction of a full-year charge.

Sum of the years’ digits

The implemented weights for a possibly fractional life are \(L,L-1,\ldots ,L-m+1\). Their sum and the cumulative first \(j\) weights are

\[ W=mL-\frac {m(m-1)}2,\qquad U_j=jL-\frac {j(j-1)}2. \]

For \(1\leq j\leq m\),

\[ D_j=B\frac {L-j+1}{W},\qquad R_j=\max \!\left (0,B-B\frac {U_j}{W}\right ). \]

For integer \(L\), this becomes the familiar sum-of-digits denominator \(L(L+1)/2\). For fractional \(L\), the stated weights, rather than an assumed integer-life formula, determine the result.

Declining balance and the straight-line switch

Let the positive factor be \(F=i\) percent and set \(q=(F/100)/L\). Start with book value \(V_0=K\). In each active year \(h\), define

\[ B_h=\max (0,V_{h-1}-S),\qquad L_h=L-h+1. \]

For ordinary declining balance,

\[ D_h=\begin {cases} B_h&L_h\leq 1,\\ \min (B_h,qV_{h-1})&L_h>1. \end {cases} \]

For declining balance with the straight-line switch,

\[ D_h=\begin {cases} B_h&L_h\leq 1,\\ \min \!\left (B_h,\max (qV_{h-1},B_h/L_h)\right )&L_h>1. \end {cases} \]

Then \(V_h=V_{h-1}-D_h\), and the requested remaining basis is \(R_j=\max (0,V_j-S)\). The last active year writes off the entire remaining basis. Earlier charges cannot push book value below salvage. The switch method compares the declining charge with straight-line depreciation of the remaining basis over the remaining life on every iteration.

These two iterative methods permit at most 100,000 active years in a requested calculation. A request beyond the asset’s life, or for a zero basis, returns via the earlier zero-result rule without iterating through those years. See chapter 13 for the register setup and commands.

C.13   Conversion definitions and factor catalog

Scale, offset, and evaluation

Each ordinary unit has a scale \(a/b\) and offset \(o\) relative to a category’s base unit. The conversion from source to destination is

\begin{equation} v_{\mathrm {base}}=(v+o_s)\frac {a_s}{b_s},\qquad v_d=v_{\mathrm {base}}\frac {b_d}{a_d}-o_d. \label {eq:math-conversion} \end{equation}

All offsets are zero except the temperature offsets listed below. Operations are performed in the shown add–multiply–divide order at current working precision; mathematically canceling factors are not a promise of a bitwise reversible round trip. A same-unit conversion also produces a value at the current precision. Conversions use the real component; they do not convert both components of a complex pair.

Every terminating decimal and rational factor in table C.2 is the exact catalog definition. This statement distinguishes the application’s chosen constants from the rounded binary values used in arithmetic; it does not assert that all physical realizations or similarly named customary units are identical. The catalog distinguishes U.S. and Imperial liquid measures, thermochemical calories, International Table BTU, and mechanical horsepower. Angle conversion additionally depends on an approximation to \(\pi \). See section 9.9.

Table C.2: Complete multiplicative catalog. Factors give base units per named unit. Units sharing a row have factors in the same order.

Unit

Factor

Length: base metre (m)

m; km; cm; mm

\(1;\ 1000;\ 10^{-2};\ 10^{-3}\)

micrometre; nanometre

\(10^{-6};\ 10^{-9}\)

inch; foot; yard

\(0.0254;\ 0.3048;\ 0.9144\)

mile; nautical mile

\(1609.344;\ 1852\)

Area: base square metre (\(\mathrm {m^2}\))

\(\mathrm {m^2};\ \mathrm {km^2};\ \mathrm {cm^2};\ \mathrm {mm^2}\)

\(1;\ 10^6;\ 10^{-4};\ 10^{-6}\)

square inch; square foot; square yard

\(0.00064516;\ 0.09290304;\ 0.83612736\)

acre; hectare

\(4046.8564224;\ 10000\)

Volume: base litre (L)

L; mL; cubic metre; cubic centimetre

\(1;\ 0.001;\ 1000;\ 0.001\)

cubic inch; cubic foot

\(0.016387064;\ 28.316846592\)

U.S. fluid ounce

\(0.0295735295625\)

U.S. pint; quart

\(0.473176473;\ 0.946352946\)

U.S. gallon

\(3.785411784\)

Imperial fluid ounce

\(0.0284130625\)

Imperial pint; quart; gallon

\(0.56826125;\ 1.1365225;\ 4.54609\)

Mass: base kilogram (kg)

kg; gram; milligram; tonne

\(1;\ 0.001;\ 10^{-6};\ 1000\)

ounce; pound

\(0.028349523125;\ 0.45359237\)

stone; short ton; long ton

\(6.35029318;\ 907.18474;\ 1016.0469088\)

Speed: base metre per second (m/s)

m/s; km/h

\(1;\ 5/18\)

mile per hour; foot per second

\(1397/3125;\ 381/1250\)

knot

\(463/900\)

Acceleration: base \(\mathrm {m/s^2}\)

\(\mathrm {m/s^2}\); foot per second squared

\(1;\ 0.3048\)

standard gravity

\(9.80665\)

Force: base newton (N)

N; kN; pound-force

\(1;\ 1000;\ 4.4482216152605\)

Pressure: base pascal (Pa)

Pa; kPa; MPa

\(1;\ 1000;\ 10^6\)

bar; millibar; atmosphere

\(100000;\ 100;\ 101325\)

pound-force per square inch (psi)

\(8896443230521/1290320000\)

torr

\(101325/760\)

Energy: base joule (J)

J; kJ; MJ

\(1;\ 1000;\ 10^6\)

watt-hour; kilowatt-hour

\(3600;\ 3600000\)

thermochemical calorie; kilocalorie

\(4.184;\ 4184\)

International Table BTU

\(1055.05585262\)

Power: base watt (W)

W; kW; MW

\(1;\ 1000;\ 10^6\)

mechanical horsepower

\(745.69987158227022\)

Time: base second (s)

s; millisecond; microsecond; nanosecond

\(1;\ 10^{-3};\ 10^{-6};\ 10^{-9}\)

minute; hour; day

\(60;\ 3600;\ 86400\)

Frequency: base hertz (Hz)

Hz; kHz; MHz; GHz

\(1;\ 1000;\ 10^6;\ 10^9\)

Torque: base newton metre (N m)

newton metre; pound-force foot

\(1;\ 1.3558179483314004\)

Table C.3: Temperature definitions relative to kelvin, using \(v_K=(v+o)a/b\).
Unit \(a\) \(b\) \(o\)
kelvin 1 1 0
degree Celsius 1 1 273.15
degree Fahrenheit 5 9 459.67
degree Rankine 5 9 0

Temperature conversion is affine rather than multiplicative. The converter applies these formulas without enforcing an absolute-zero physical limit. A temperature difference is a different quantity: applying the absolute temperature offset to a difference would be inappropriate.

The angle catalog is radian, degree, gradian, and turn, with radian factors

\[ 1,\qquad \pi /180,\qquad \pi /200,\qquad 2\pi \]

respectively. Angle conversion explicitly passes through radians using the current value of \(\pi \). Selecting source and destination angle units in the converter does not change the calculator’s DEG/RAD/GRAD setting.

C.14   Limits and independent checks

Table C.4: Principal numerical and operational limits.

Quantity

Current limit or rule

Working precision

16–10,000 decimal digits through settings; default 600.

Display digits

0 through the current working digit count; default FIX 4.

RPN stack setting

Fixed depth 2–1,000, or 0 for unlimited; default 5. Unlimited remains constrained by available resources.

Ordinary memory

Ten registers, R0–R9.

Real-mode factorial

Integer argument from 0 through 10,000. Complex mode also permits the Gamma extension, including noninteger real inputs; see section C.4.

Permutations and combinations

Integer real components with \(0\leq k\leq n\leq 10{,}000\), even in complex mode.

Real integer root index

Nonzero, between \(-1{,}000{,}000\) and \(1{,}000{,}000\).

Complex powers

MPC power and integer-exponent primitives; finite exponent range and working precision still apply.

Complex gamma

Requested precision no greater than 10,000 decimal digits; poles excluded.

Nonreal erf and erfc

Approximate radius-100 input limit and finite convergence budget; real arguments use a separate path. See section C.4.

Cash-flow bank

1,000 expanded positions including CF0; selected last index 0–999 within the list.

Cash-flow repetition

Integer frequency 1–1,000, subject to total bank capacity.

AMORT block

Integer count 0–100,000.

Iterated depreciation

At most 100,000 active years for DB or the DB/SL switch.

Dates

Gregorian years 1–9999; integer date-addition offsets within \(\pm 3{,}652{,}058\), with the result still in range.

Financial root search

200 iterations per stage, 100,000 evaluations, fixed transformed-variable tolerance; see section C.9.

ALG streaming editor

4,096 tokens, nesting depth 128, and a 10,000-character numeric-entry stream limit.

ALG worksheet field

100,000 source characters, 4,096 tokens, and nesting depth 128.

The RPN numeric-entry editor has no configured character cap. Available memory and processing time still place practical limits on long entries and unlimited stacks.

An effective numerical check matches the problem’s structure. Substitute a TVM result back into equation (C.5); evaluate NPV at an IRR; compare book-value changes with depreciation; check a conversion’s units and inverse; and compare a regression with centered data. Use freshly entered inputs when changing precision, preserve cash signs and period units, and distinguish a different branch or date convention from a numerical error. The worked chapters supply complete operating examples; chapter 14 explains how to diagnose unexpected behavior and preserve a reproducible calculation.