Back when I was a C++ newbie, I decided to write a rational number class because I thought it would be a good exercise. I revised it and added features over the years as I learned new stuff (I/O manipulators, for example). I looked around my computer for it this morning and found a version that I wrote over a decade ago when I still didn’t have even a C++11 compiler to work with.
About 11 or 12 years ago, WG21’s numerics study group was thinking about publishing a Technical Specification (TS, a kind of warning about possible future standardization) that would propose some new number types (fixed-point types, an unbounded integer, things like that). I confidently raised my hand and said that I had a rational number that I could add and proposed what would eventually morph into this*. That “Numbers TS” is no longer in the works, so my rational number died.
I think I’ll revisit that to bring it at least to the C++20 level and implement it using the bigint class that I mentioned in the last post to avoid overflow. I also want to put the I/O manipulators back just because I think they’re Really Cool. 😎
That should keep my brain working for a little while longer.
*Starting with the “[rational.math] Rational math” section, that’s what much of the C++ standard reads like. It’s most definitely not a tutorial. 😎