CLibs
Loading...
Searching...
No Matches
math.h File Reference

Go to the source code of this file.

Functions

Mathematical uint64_t digitsof (uint64_t num, unsigned base)
Mathematical int64_t power (int64_t base, unsigned exp)
Mathematical uint64_t upower (uint64_t base, unsigned exp)
Mathematical uint64_t reverse_integer (uint64_t n, unsigned base)
Mathematical uint64_t get_next_power_of_two (uint64_t)
Mathematical uint64_t get_prev_power_of_two (uint64_t)

Function Documentation

◆ digitsof()

Mathematical uint64_t digitsof ( uint64_t num,
unsigned base )

Math functions & other number operations. Returns how many digits ‹num› has in a specified base

Parameters
numAny natural number
baseWhole number bigger than 0
Returns
Number of digits. For (num = 0) the function returns 0; if base < 0, the function returns -1

◆ get_next_power_of_two()

Mathematical uint64_t get_next_power_of_two ( uint64_t )
Returns
smallest power of two bigger than the parameter

◆ get_prev_power_of_two()

Mathematical uint64_t get_prev_power_of_two ( uint64_t )
Returns
biggest power of two smaller than the parameter

◆ power()

Mathematical int64_t power ( int64_t base,
unsigned exp )

base ^ (to the power of) exp

Parameters
basenumber
expexponent
Returns
base ^ exp

◆ reverse_integer()

Mathematical uint64_t reverse_integer ( uint64_t n,
unsigned base )

Reverses the digits of the number n. Ignores lead zeroes, works in any base.

Example:

reverse_integer( 123, 10 ) // => 321
reverse_integer( 0xFA, 16 ) // => 0xAF
reverse_integer( 0b0101, 2 ) // => 0b101
Mathematical uint64_t reverse_integer(uint64_t n, unsigned base)
Parameters
nnumber to be reversed
basenumeric base of the number
Returns
digit-wise reverse of the original

◆ upower()

Mathematical uint64_t upower ( uint64_t base,
unsigned exp )

base ^ (to the power of) exp

Parameters
baseunsigned number
expexponent
Returns
base ^ exp