Estoy tratando de hacer la división en un uint128_t
que se compone de 2 uint64_t
s. Curiosamente, la función funciona para uint64_t
s con solo el valor inferior establecido y el valor superior = 0. No entiendo por qué.División que no cruza sobre bytes
Aquí está el código para la división y poco cambio
class uint128_t{
private:
uint64_t UPPER, LOWER;
public:
// lots of stuff
uint128_t operator<<(int shift){
uint128_t out;
if (shift >= 128)
out = uint128_t(0, 0);
else if ((128 > shift) && (shift >= 64))
out = uint128_t(LOWER << (64 - shift), 0);
else if (shift < 64)
out = uint128_t((UPPER << shift) + (LOWER >> (64 - shift)), LOWER << shift);
return out;
}
uint128_t operator<<=(int shift){
*this = *this << shift;
return *this;
}
uint128_t operator/(uint128_t rhs){
// copy of numerator = copyn
uint128_t copyn(*this), quotient = 0;// constructor: uint128_t(T), uint128_t(S, T), uint128_t(uint128_t), etc
while (copyn >= rhs){
// copy of denomiator = copyd
// temp is the current quotient bit being worked with
uint128_t copyd(rhs), temp(1);
// shift the divosr to the highest bit
while (copyn > (copyd << 1)){
copyd <<= 1;
temp <<= 1;
}
copyn -= copyd;
quotient += temp;
}
return quotient;
}
// more stuff
};
favor ignorar mi indiferencia evidente para la gestión de la memoria.
En realidad, todas las tapas se reserva generalmente para identificadores de preprocesador. –
Bueno, algunos identificadores de preprocesador son en realidad constantes por lo que sigue teniendo la razón, pero sí, en un sentido más amplio, todas las macros están escritas en mayúsculas –
, no ha cambiado nada. :(¿Hay algo mal con el operador de la división? Parece estar atascado en el ciclo 'while (copyn> (copyd << 1))' – calccrypto