ported base math functions to C++