forked from xiaoyeli/superlu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[matgen] Cleanup power with integer exponent
Add header. Include header instead of forward declarations. Rename function to no longer follow Fortran naming scheme. Call by value instead of reference. Move float and double functions into a single file. Add Doxygen documentation.
- Loading branch information
Showing
11 changed files
with
96 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*! \file | ||
* \ingroup TestingMatgen | ||
* \brief Power with integer exponent | ||
*/ | ||
|
||
/*! | ||
* Power with integer exponent | ||
* | ||
* Implemented as Exponentiation by Squaring for speed. | ||
* | ||
* \param[in] base base as double value | ||
* \param[in] exp exponent as integer value | ||
* \return Computes the value of \p base raised to the power \p exp | ||
*/ | ||
double powi(double base, int exp) | ||
{ | ||
double x = base; | ||
int n = exp; | ||
double pow = 1.0; | ||
|
||
if (n != 0) { | ||
if(n < 0) { | ||
n = -n; | ||
x = 1 / x; | ||
} | ||
for( ; ; ) { | ||
if(n & 01) | ||
pow *= x; | ||
if(n >>= 1) | ||
x *= x; | ||
else | ||
break; | ||
} | ||
} | ||
return pow; | ||
} | ||
|
||
/*! | ||
* Power with integer exponent | ||
* | ||
* Implemented as Exponentiation by Squaring for speed. | ||
* | ||
* \param[in] base base as float value | ||
* \param[in] exp exponent as integer value | ||
* \return Computes the value of \p base raised to the power \p exp | ||
*/ | ||
float powif(float base, int exp) | ||
{ | ||
float x = base; | ||
int n = exp; | ||
float pow = 1.0; | ||
|
||
if (n != 0) { | ||
if (n < 0) { | ||
n = -n; | ||
x = 1 / x; | ||
} | ||
for ( ; ; ) { | ||
if (n & 01) | ||
pow *= x; | ||
if (n >>= 1) | ||
x *= x; | ||
else | ||
break; | ||
} | ||
} | ||
return pow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
double powi(double base, int exp); | ||
|
||
float powif(float base, int exp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters