Long overflow in AbsoluteDate
If the constructor AbsoluteDate(AbsoluteDate, double)
is called with a large double value, or if the epoch of the first argument is already large then overflow can occur in epoch = since.epoch + dl
if the sum is greater than Long.MAX_VALUE
. FastMath.addExact()
could be used to throw an exception if overflow does occur. If overflow does occur the values should probably be set equal to past/future infinity. This can occur in the other constructor that sets epoch
as well. A more conservative approach would be to return infinities if offset
is not in the interval [0, 1).
Examples:
AbsoluteDate.J2000_EPOCH.shiftedBy(Long.MAX_VALUE).shiftedBy(Long.MAX_VALUE).toString()
// result is "2000-01-01T11:58:53.816" but it should be far in the future
AbsoluteDate.J2000_EPOCH.durationFrom(AbsoluteDate.J2000_EPOCH.shiftedBy(Long.MIN_VALUE))
// result is -9.223372036854776E18 but it should be positive
Not sure if this has an practical relevance.