Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * An integer based power function
0004  *
0005  * Derived from drivers/video/backlight/pwm_bl.c
0006  */
0007 
0008 #include <linux/export.h>
0009 #include <linux/math.h>
0010 #include <linux/types.h>
0011 
0012 /**
0013  * int_pow - computes the exponentiation of the given base and exponent
0014  * @base: base which will be raised to the given power
0015  * @exp: power to be raised to
0016  *
0017  * Computes: pow(base, exp), i.e. @base raised to the @exp power
0018  */
0019 u64 int_pow(u64 base, unsigned int exp)
0020 {
0021     u64 result = 1;
0022 
0023     while (exp) {
0024         if (exp & 1)
0025             result *= base;
0026         exp >>= 1;
0027         base *= base;
0028     }
0029 
0030     return result;
0031 }
0032 EXPORT_SYMBOL_GPL(int_pow);