I want to provide software to compute with "integer complex numbers", that live in $\mathbb{Z}\times i \mathbb{Z}$, rather than the $\mathbb{C}$. Some operations are going to give results that are outside of $\mathbb{Z}\times i \mathbb{Z}$. What should I do with those? I see at least two options: 1. disallow them as making no sense for this restriction of $\mathbb{C}$, 2. allow the operation, but round automatically to the closest element of $\mathbb{Z}\times i \mathbb{Z}$, giving some well-defined meaning to "closest". What would be the most usual approach in mathematical software?
1 Answer
Mathematical software almost never defines the result of integer operations in terms of "round to nearest". For example, in C, C++, Fortran, etc. the result of dividing a positive integer by another positive integer always rounds downward. (IN general, the rule in those languages is "round toward zero."
If forced to provide a complex template specialization in C++, I would hold my nose and stick with that convention, rounding both the real and imaginary parts toward zero. Thus $$\frac{4-11i}{3-2i} "=" 2-i$$ because $\frac{34}{13}$ "rounds" to $2$ and $-25/13$ "rounds" to $-1$.
exp(2+3i)
, for example, what would be reasonable to return? Or what do other existing software, like pari, ... do? $\endgroup$