Yanked code from pow() implementation.