| Server IP : 217.160.0.212 / Your IP : 216.73.216.141 Web Server : Apache System : Linux www 6.18.51-i1-ampere #1196 SMP Fri Sep 11 20:43:55 CEST 2026 aarch64 User : sws1073854427 ( 1073854427) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/pythran/pythonic/numpy/ |
Upload File : |
#ifndef PYTHONIC_NUMPY_BASEREPR_HPP
#define PYTHONIC_NUMPY_BASEREPR_HPP
#include "pythonic/include/numpy/base_repr.hpp"
#include "pythonic/utils/functor.hpp"
#include "pythonic/types/ndarray.hpp"
PYTHONIC_NS_BEGIN
namespace numpy
{
types::str base_repr(long number, long base, long padding)
{
types::str res;
// check that the base if valid
if (base < 2 || base > 16) {
return res;
}
int const ndigits =
(number == 0 ? 1
: std::ceil(std::log(std::labs(number)) / std::log(base)));
int const effective_padding =
padding - ((number == 0) && (padding > 0) ? 1 : 0);
res.resize(ndigits + effective_padding + (number < 0 ? 1 : 0));
// Apply negative sign
auto it = res.chars().begin();
if (number < 0)
*it++ = '-';
// Apply padding
std::fill(it, std::next(it, effective_padding), '0');
auto rit = res.chars().rbegin();
long quotient = std::labs(number);
do {
const long tmp = quotient / base;
*rit++ = "0123456789ABCDEF"[quotient - (tmp * base)];
quotient = tmp;
} while (quotient);
return res;
}
}
PYTHONIC_NS_END
#endif