Borrowed Spout's math package.