I ported all of the utility routines over to the Java side and wrote unit tests for them. Whenever I saw an error in the results on the C++ side, I'd go add another case or three to the Java tests, figure out what was going wrong, patch the Java code, patch the C++ code, and go run another case on the C++ side.
After a couple of cycles of this, everything worked.
*whee*