velnias75 / rational

A C++ rational (fraction) template class
GNU General Public License v3.0
8 stars 0 forks source link

support for Gaussian integers #2

Open velnias75 opened 8 years ago

velnias75 commented 8 years ago

By Melchoir via Reddit

A Gaussian integer is a complex number where the real and imaginary parts are both integers. In other words, a thing of the form a+bi where a and b are integers. I think it can even be implemented as std::complex. Some salient points are:

Gaussian integers and Gaussian rationals are both interesting types. It would be nice if one could define a Gaussian integer type and, with a little extra effort, get the rational type by applying your template to it. In the terminology of pure mathematics, your template implements a field of fractions, which is meaningful for any integral domain, including the ordinary integers.

I understand the point about designing the template for completeness. My point is that as a potential user of the library, I would be worried that, for example, the implementation of Rational::operator+= secretly performs some normalization that depends on the existence of T::operator<. This information is impossible to get just from reading the code, and I would dread having to test it out myself, only to pull my hair out deciphering the compiler's error messages. Even if it compiles, I would be worried that it makes some assumption about the behavior of the < operator that is violated by my storage type, and the compiler wouldn't even be able to detect that. This might very well be the case for the Gaussian integers, which I would count as an "exotic" storage type.

Eh... I would try adding support for Gaussian integers myself, but it feels like it might be a lot of work. :)

velnias75 commented 8 years ago

Without an Gauss integer class I have simply to less knowlegde to even begin with work :-(

I tried to use std::complex, but I fail because except of the for basic arithmetic operators almost everything is missing.

Instantiation fails already because I have no GCD for it.

velnias75 commented 8 years ago

Gaussian integers on Stackoverflow