Skip to content

Commit

Permalink
feat: add ll_pow
Browse files Browse the repository at this point in the history
  • Loading branch information
molingyu committed Sep 13, 2024
1 parent 4f182a8 commit 6edd532
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,24 @@ bool utf8_chr_each( const char* utf8_str, bool ( *each_block )( size_t, const ch
}
return true;
}

long long ll_pow( int base, int exp )
{
long long result = 1;
if ( exp < 0 )
{
return 0;
}

while ( exp > 0 )
{
if ( exp % 2 == 1 )
{
result *= base;
}
base *= base;
exp /= 2;
}

return result;
}
2 changes: 2 additions & 0 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,5 @@ size_t utf8_strlen( const char* utf8_str );
int utf8_char_length( unsigned char c );

bool utf8_chr_each( const char* utf8_str, bool ( *each_block )( size_t, const char*, void* ), void* extra_data );

long long ll_pow( int base, int exp );

0 comments on commit 6edd532

Please sign in to comment.