Staging
v0.5.2
https://github.com/torvalds/linux
Raw File
Tip revision: 7e57714cd0ad2d5bb90e50b5096a0e671dec1ef3 authored by Linus Torvalds on 27 February 2022, 22:36:33 UTC
Linux 5.17-rc6
Tip revision: 7e57714
int_pow.c
// SPDX-License-Identifier: GPL-2.0
/*
 * An integer based power function
 *
 * Derived from drivers/video/backlight/pwm_bl.c
 */

#include <linux/export.h>
#include <linux/math.h>
#include <linux/types.h>

/**
 * int_pow - computes the exponentiation of the given base and exponent
 * @base: base which will be raised to the given power
 * @exp: power to be raised to
 *
 * Computes: pow(base, exp), i.e. @base raised to the @exp power
 */
u64 int_pow(u64 base, unsigned int exp)
{
	u64 result = 1;

	while (exp) {
		if (exp & 1)
			result *= base;
		exp >>= 1;
		base *= base;
	}

	return result;
}
EXPORT_SYMBOL_GPL(int_pow);
back to top