]> Git Repo - linux.git/blame - lib/math/int_pow.c
Merge branch 'for-linus-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad...
[linux.git] / lib / math / int_pow.c
CommitLineData
9f615894
AS
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * An integer based power function
4 *
5 * Derived from drivers/video/backlight/pwm_bl.c
6 */
7
8#include <linux/export.h>
9#include <linux/kernel.h>
10#include <linux/types.h>
11
12/**
13 * int_pow - computes the exponentiation of the given base and exponent
14 * @base: base which will be raised to the given power
15 * @exp: power to be raised to
16 *
17 * Computes: pow(base, exp), i.e. @base raised to the @exp power
18 */
19u64 int_pow(u64 base, unsigned int exp)
20{
21 u64 result = 1;
22
23 while (exp) {
24 if (exp & 1)
25 result *= base;
26 exp >>= 1;
27 base *= base;
28 }
29
30 return result;
31}
32EXPORT_SYMBOL_GPL(int_pow);
This page took 0.076225 seconds and 4 git commands to generate.