Since negative julian dates are supported, I ended up writing my own modulo function in C to emulate ruby's, so that a positive number would always be returned even if the dividend was negative.