Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

power function for integers?

Moderators: kris

Posted: 09/23/07 18:44:31


I would like to ask for exp power-functions for integers (integer base, nonnegative integer exponent).

For the exponent, ubyte would be sufficient. So the signature might be something like

long exp(long,ubyte)

For example: exp(3,7) would give 37 = 2187

The overflow case needs to be considered, for efficiency it might be the best simply not to care for overflows.

Author Message

Posted: 09/26/07 11:03:24

import tango.math.Math;

long intpow(long base, ubyte exponent) {

return rndlong(pow(base, exponent));