Skip to content
Snippets Groups Projects
Commit cc598bb6 authored by Dirk Zimoch's avatar Dirk Zimoch
Browse files

optimize ** (power) operator

parent 6d7b883b
No related branches found
No related tags found
No related merge requests found
...@@ -66,12 +66,16 @@ static int parseValue(const char **pp, long *v) ...@@ -66,12 +66,16 @@ static int parseValue(const char **pp, long *v)
static long ipow(long base, long exp) static long ipow(long base, long exp)
{ {
long v; long val;
if (exp < 0) return 0; if (exp == 2) return base*base;
if (exp == 3) return base*base*base;
if (exp == 1) return base;
if (exp == 0) return 1; if (exp == 0) return 1;
v = base; if (exp < 0) return 0;
while (--exp) v *= base; /* optimize this! */ val = ipow(base,exp>>1);
return v; val *= val;
if (exp&1) val *= base;
return val;
} }
static char parseSep(const char **pp, const char *seps) static char parseSep(const char **pp, const char *seps)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment