More on the rational Class

Andrew Dalke did a few tests of my rational number library (thanks) and I thought it deserved a post of its own.

The first links to code in the function float_as_integer_ratio_impl(), which is the C implementation of the Python method as_integer_ratio() …

OK, I found it.  Yeah, I tried to use frexp(); but I tried to do some bit twidling to get the mastissa bits as an integer and that was a big mistake.  It’s easy once you know how to do it. 😎

I’ll add something like this to my rational class; but I’m not sure yet whether I want to make it only for FLT_RADIX == 2 and whether I want to allow the user to do something less than an exact conversion, falling back on the continued fractions routine if I need to.

I wrote a quick and dirty program to do the tests mentioned in the comment and compiled it:

– for Windows using an ancient Microsoft compiler which doesn’t conform even to C++11 (although it has rvalue references and type traits templates which is enough for it to get through my bignum stuff), and with a long double that’s just a double.

– for Linux using a somewhat more up-to-date GCC (C++14 at least), and with a bigger long double.

I got two different sets of results (Windows, Linux), possibly due to differences in the long double format.

– The Windows version had no trouble with either 0.0869406496067503 or 1.1100695288645402e-29, but it failed on 0.9999999999999999.

– The Linux version failed on both 0.0869406496067503 and 1.1100695288645402e-29, but it worked on 0.9999999999999999.

– Both failed on nextafter(1,0).

… 1.1100695288645402e-29 gives a “Can’t convert NaNs or infinities to bigint” because the
val0 = 1.0 / (val0  static_cast(int0)); step results in an inf.

(That should be static_cast<long double>(int0)…either WordPress or the browser itself thought that the <long double> was an unrecognized HTML tag.)

My Linux version reports that as well.  That’s a bug in my code which I’ll have to figure out if I decide to keep the continued fractions around for support of either FLT_RADIX != 2 or inexact conversions.

I urge you to look towards an existing library if all you need is SQL interoperability.

Actually, what I need is to keep my mind active in my retirement. 😎

There are some third-party database access libraries out there; but they look to me like they were written by teenagers sitting in their basements going, “Cool!”; and I’m not sure that they scale up to real-world applications.  For example, there’s one called SOCI that actually tries to make database tables act like iostreams.

Also, I think I can make my library act like a Web service client as well, and maybe even access the cloud.  We’ll see…

The Latest Cancer News

As I’ve said before, I signed up for a study of the effectiveness of prophylactic radiation to keep the cancer out of the brain.

I got a call this morning saying that I’d been randomized into the control group, so I won’t be getting the radiation; but I’ll do all the rest of it:  CT and MRI scans, some blood tests, and some tests of my cognitive abilities (I hope more interesting than the test that Trump bragged about passing, but we’ll see).  The various tests will happen (IIRC) every three months for two years.

With any luck, I’ll be able to do all the tests at an outpatient facility that’s just a ten minute drive from where I live; but it’s unclear whether some special requirements of the study mean that I have to get the scans at the hospital, a 35 minute drive at the best of times.  I hope to find out more about that tomorrow morning.

I’ve had the first scans already, and I’ll get the lab work done and the first cognitive tests tomorrow morning at the hospital (but I don’t have to show up until 10:30, so that’s after the rush hour).

Update, 2024-01-07:  the test of my cognitive abilities that I took on the 4th was indeed more interesting than the one that Trump bragged about passing, but still nothing to brag about. 😎