My Next Excuse for Riding Trains

I won’t be blogging about riding trains until November when I’ll be traveling to Wrocław, Poland to attend a meeting of the ISO C++ standards committee, but I’m starting to think about it, and I’ve worked up a possible itinerary that includes a three-day conference in Berlin the week before and a one-day conference in Wrocław afterwards.

As I’ve said before, I like to fly Icelandair across the Pond because I like to get off the plane and stretch my legs in Keflavík.  Also, because travel to these meetings is the only thing I spend my fun money on, I’m fortunate to be able to afford Icelandair’s Saga class if I don’t try to afford other stuff that I don’t really want that much anyway.  (Business class on other airlines would probably be out of my price range; and besides, I wouldn’t want to sit in an airplane long enough to get all the way to Europe in one fell swoop.)

Unfortunately, Icelandair serves Berlin only five days per week, so the eastbound trip doesn’t work well.  I’m currently thinking about going a day late and missing almost all of the first day of Meeting C++.  I could fly into Frankfurt instead and take an ICE directly from the airport to Berlin; but then I’d have to return from Frankfurt to get the round-trip air fare; and getting from Wrocław to Frankfurt by train doesn’t look easy.

Update 2024-04-20:  I think I’ve found a way to get from Wrocław to the Frankfurt airport by train, and I like that better.  The link above is to the new version.  The version flying into and out of Berlin is still available here.

Nokia will be sponsoring a one-day conference called code:dive that’s still not officially announced, so I don’t know when or where it’ll be.  My rough itinerary assumes that it’ll be in the same hotel the Monday after the ISO meeting, which could be wrong; so the westbound trip is still subject to change.

Update, 2024-04-17:  I’ve added another option for the first leg that saves a long layover in Chicago.  That train originates in Kansas City and is often delayed on the former MoPac west of St. Louis, so I’m a bit leery about counting on it:  missing the very first connection would likely destroy the whole trip.

I checked out train 318’s arrival times in Chicago and the likelihood of making my connection back to the 1st of October, and it doesn’t look too dangerous; but I’m still not sure I’d want to chance it.  (If I look only at Mondays, which is the weekday I’ll be traveling, I never miss the connection on any of the 29 days; but it’s not clear whether the weekday actually has any effect.)  I probably won’t be making any reservations until the end of July or so, so I’ll check again then.  I’ll probably just stick with the Texas Eagle in any event since that will allow checking a bag all the way to New York.  (The Missouri-Illinois corridor trains don’t have checked baggage service.)

I’ve also been told that Nokia’s code:dive conference will definitely be on Monday, November 25th, but not at the Double Tree where the WG21 meeting will be.

Time Zones in C++

I think I have my timezone class ready for prime time, so I should be just about ready to finish the larger civil time library (which I put on hold because a couple of the classes depend on timezone).

But as I write this, I remember that there’s one thing I haven’t tested yet:  the option of reading TZ and TZ_ROOT environment variables using std::getenv() before the timezone class gets used for anything.  I do that magically with some tricky code that has the odor of the poltergeist anti-pattern; so I need to create the TZ and TZ_ROOT environment variables on my Windows box and make sure that that works.  I don’t see any reason why it won’t, so I’ll say tentatively that I’m done.

Questions for Mac Users

I’ve been slow to finish testing my C++ time zone code because I’ve had other things to do; but I think I have it ready for prime time.

But now, in the spirit of the analysis paralysis anti-pattern πŸ˜Ž (I’m having fun in my retirement, don’tcha know), I’ve decided that I’d like to make it magically portable to the Mac if I can.

1.  Does the Mac have the Zoneinfo data somewhere?

2.  Do you have POSIX-style environment variables (possibly called TZ_ROOT and TZ) for
  a.  the directory where the Zoneinfo compiled binaries are found, and/or
  a.  your local time zone?

If Macs are at all Linux-like except for having the environment variables, TZ_ROOT could be /usr/share/zoneinfo”; and TZ could be localtime or, in the U.S. central time zone for example, either America/Chicago or CST6CDT,M3.2.0,M11.1.0”.

And for those doing C++ work with some version of GCC,

3.  is there some macro or other predefined identifier that says we’re compiling for a Mac rather than some other POSIX-like O/S?

I could probably go to an Apple store, fire up a Korn (or other) shell, and find out what I need for myself; but I’m hoping that there’s somebody reading this blog who already knows the answers off the top of their head.


Update:  thanks to robert79 for some good information about Macs.

It looks like they work pretty much like Linux, except that the filesystem has no symbolic link called localtime, so I still have no clue how a program can discover what the local time zone is.  There’s certainly some way to set the time zone through the UI, but I still need to find out how to discover that setting programmatically.  Maybe Google will help.

Update2:  well, that was easy.  I should have just Googled from the get-go.

It seems that, in POSIX systems generally, /etc/localtime is usually a symbolic link to the real file.  There should also be a file called /etc/timezone.

My Debian Linux box, a VPS actually, is somewhere in England; so /etc/localtime is a symlink to /usr/share/zoneinfo/Europe/London and /etc/timezone is a plain text file that contains just Europe/London”.

I don’t need any code changes, just some remarks in the documentation that the library will work on a Mac; and I still have to proofread that anyway.

Thanks again to robert79.

Time Zones

I’ve been debugging my timezone stuff somewhat casually, but I think I have it to the point where I’m willing to admit that I wrote it. πŸ˜Ž

This paper also references a trivial library that I’ve mentioned before.

If anybody who cares can think of any cool features that I should add, please let me know, either in the comments or in a private e-mail message.

I can now finish my larger civil time library which contains classes that are intended to be the C++ equivalents of SQL’s datetime types, which in turn will be part of a database access library.  (I’m still having fun in my retirement.)

Some Fun Time Zone Geekiness

There were a few e-mail messages on the FtB backchannel a little while ago.  An FtB blogger who lives in Ireland was wondering when the next FtB Podish-Sortacast will happen (, scroll down a bit), probably just under an hour from when I get this posted.

That got me to thinking about civil time in the Irish Republic.  It winds up that they observe the same time as Great Britain and Northern Ireland, except they get there with rather tortured reasoning.

In the U.K., they switch from “Greenwich Mean Time” (GMT, same as UTC+0) to “British Summer Time” (BST, UTC+1) on the last Sunday in March at 01:00:00 local wall clock time, and they switch back from BST to GMT on the last Sunday in November at 02:00:00 local wall clock time.

In Ireland, they switch from ”Irish Standard Time” (IST, UTC+1) to GMT on the last Sunday in November at 02:00, and they switch back from GMT to IST on the last Sunday in March at 01:00.

Yes, really. Go figure. πŸ˜Ž

The POSIX TZ environment variable for Europe/London:  GMT0BST,M3.5.0/1,M10.5.0
The POSIX TZ environment variable for Europe/Dublin:  IST-1GMT0,M10.5.0,M3.5.0/1

Why did they bother?

A Couple of C++ Quickies

I wrote two fairly trivial libraries to support my development of the timezone class that I’ve mentioned before.

1.  Reading Directories in C++ describes a class that loops through directories.  It’s portable to both POSIX and Windows so that you don’t have to do that in two very different ways.

2.  Getting Zoneinfo Data on Windows describes a simple way to do what the title says along with a couple of functions that let you create and delete symbolic links on Windows.

Both of those are really old news, and neither has any great ideas of my own, so all that code is in the public domain.

The timezone class is finished, but I still need to do some testing before I release the code to the world and, perhaps, embarrass myself. πŸ˜Ž  I hope to have that done later today.

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.

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.

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…