Reading Directories in C++

This one is trivial.

For testing my timezone code, I often need to recurse through all the directories where the Zoneinfo binary files are.  I got tired of rewriting the programs depending on whether I was testing on Linux or Windows, so I decided to write a little framework that would be portable to both operating systems.  It doesn’t solve all the problems (the two systems provide different information about directory entries), but at least I don’t have to completely restructure the main loops. 😎

There are no new ideas here:  how to loop through directories is really old news; and since it’s not particularly original on my part, all the code is in the public domain.

Time Zones in C++

I’m back to working on a database access library in C++ and, at present, I’m developing a library of civil time classes that would mimic SQL’s datetime types.  In the next two or three days, I hope to have a timezone class ready for prime time; and I’ve decided to document it separately from the rest of the civil time library because there’s no reason why it couldn’t be a stand-alone class in its own right.

I don’t have the final code ready to share yet, but I wanted to make the design available while the class is still under development in case there’s anybody out there who would like to suggest any additional features that I haven’t thought of.

Is there anything else you think I need?

Update:  I just found out that Windows’ filesystem does indeed support symbolic links.  (I’m not sure what planet I’ve been living on.)  I’ve also figured out an easy way to create a .zip archive with the symlinks in it* and unzip that on my Windows box.  I guess I have a bit of a redesign to work on. 😎

*I can also create a .tar.gz that’s about one fifth the size of the .zip file, but I don’t see how to get the links as links (rather than copies of the file), and the .zip file is only about 2.5Mb.

The Big Picture

Robert Reich likes to draw cartoons.

I’m on one of his e-mail lists, and early this morning I got a message that contains a link to a video of him drawing a really big one (ca. 6½ minutes) explaining how the economy got into the state that it’s in.

That was cute; but there should be an image, like maybe a JPEG, of the completed drawing so that we can see the whole thing all at once.  It doesn’t matter if it’s huge:  it would be good to be able to scroll around and zoom in/out.

Travel to Wrocław in the Fall

I got an e-mail message last night giving the dates are for the C++ standards committee meeting in Wrocław, Poland, so I’ve made some preliminary guesses about what my travel itinerary might look like.  There are still some unknowns, however; although it’ll almost certainly be Amtrak between St. Louis and Boston, Icelandair between Boston and some city in Europe, and then one or more trains to/from Wrocław.

As I’ve said before, I don’t like flying very much; and so I take Icelandair to/from Boston, mostly because I like getting off the plane and stretching my legs in Keflavík.  Also, I can usually afford Saga Class on Icelandair if I don’t try to afford other stuff that I don’t really want that much anyway; but business class on other airlines is typically pricier.

We’ll see how it actually works out…

More on Big Numbers in C++

I’ve been rather lackadaisical about fixing my “big number” classes, but I’ve finally gotten up off the couch, and I have new versions available.

I’ve changed the names of the bigint and bigdec classes to integer and decimal, respectively, because I thought the “big…” names smelled of Java.  I also wrote a small Web page that ties the three classes together.

In a comment to a previous post, Andrew Dalke suggested some additional values I could test; and, sure enough, I found a bug (thanks).  (The bug was actually in what’s now called the integer class:  I hadn’t guarded against aliasing of the operands to expressions like x *= x.)

I think I remember someone suggesting that some users might prefer classes with “more features”.  What additional features did you have in mind?  Don’t suggest trig. functions and the like:  I’ve limited the <cmath>-like functions that take decimal and rational arguments to those that return exact values.  (You might be able to talk me into square root, but that would be successive approximation using Newton’s method which is what I know how to write.  I already have a version of the rational class that has quiet NaNs and infinities and a spaceship operator, but I’m not sure I like it.)

As I’ve said before, these classes are not intended for serious numerical work; and numerics experts probably already know where to find better implementations, or could write such themselves.

Update, 2024-02-05:  I woke up this morning having in my mind a way to make rational comparisons a bit quicker, so I made that change.  I also noticed that I had failed to remove an isinf() test of the accuracy argument to the conversion from floating point values.  (In the previous version, passing a NaN for the accuracy would trigger an exact conversion using std::frexp().  In the current version, any non-finite accuracy will do that.)

By the way, if anybody out there has access to a C++ implementation where FLT_RADIX != 2, I’d appreciate a test of the frexp() business.  I have access only to boxes where FLT_RADIX is 2.

U.S. Sanctions on West-Bank Israelis

16:00 UTC−6:  DW News leads with a report that Biden has signed an executive order imposing economic sanctions on four named Israelis who were involved in anti-Palestinian violence in the West Bank.  I see this as a baby step in the right direction.  We’ll see whether U.S. policy toward Israel develops any morality.  Stay tuned…

16:30−6:  BBC World News America leads with the same story.

17:10:  my local TV news has a couple of sentences about the sanctions.  They say it’s in response to the killing of a Palestinian-American teenager.

17:30:  no mention of the sanctions on NBC Nightly News.

18:00:  nothing about the sanctions during the headlines on PBS Newshour either.

Now I’m saddened again.  NBC did have a short report about a growing movement within the Arab-American community for sitting out the next election.  They won’t vote for Trump, but they don’t think they can vote for Biden either.  Let’s hope that that doesn’t give the election to Trump.  Maybe there’s some good news in John Morales’ comment below.

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. 😎