Use unsigned long longs

This commit is contained in:
ItsDrike 2025-02-26 15:20:35 +01:00
parent c4d48e982a
commit 767f706fea
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
2 changed files with 24 additions and 24 deletions

View file

@ -8,11 +8,11 @@ FactorizationController::FactorizationController(QObject* parent) :
assert(connect(&m_timer, &QTimer::timeout, this, &FactorizationController::onTimerTick));
}
long long FactorizationController::number() const {
unsigned long long FactorizationController::number() const {
return m_originalNumber;
}
long long FactorizationController::curFactNumber() const {
unsigned long long FactorizationController::curFactNumber() const {
return m_currentFactNumber;
}
@ -85,19 +85,19 @@ void FactorizationController::setIterationsPerCycle(int number) {
emit iterationsPerCycleChanged();
}
long long FactorizationController::currentFactor() const {
unsigned long long FactorizationController::currentFactor() const {
return m_currentFactor;
}
long long FactorizationController::stopFactor() const {
unsigned long long FactorizationController::stopFactor() const {
return m_stopFactor;
}
QList<long long> FactorizationController::factors() const {
QList<unsigned long long> FactorizationController::factors() const {
return m_factors;
}
void FactorizationController::start(long long number) {
void FactorizationController::start(unsigned long long number) {
m_originalNumber = number;
m_currentFactNumber = number;
m_currentFactor = 2;
@ -106,7 +106,7 @@ void FactorizationController::start(long long number) {
m_factors.clear();
if (m_useSqrtOptimization) {
// we could also just compute this every time, but sqrt is pretty expensive
m_stopFactor = static_cast<long long>(std::sqrt(m_currentFactNumber));
m_stopFactor = static_cast<unsigned long long>(std::sqrt(m_currentFactNumber));
} else {
m_stopFactor = m_currentFactNumber - 1;
}
@ -216,7 +216,7 @@ void FactorizationController::factorize() {
// the new number being factorized, rather than keeping it at the original number.
// (This might make the progress bar jump radically)
if (m_useSqrtOptimization) {
m_stopFactor = static_cast<long long>(std::sqrt(m_currentFactNumber));
m_stopFactor = static_cast<unsigned long long>(std::sqrt(m_currentFactNumber));
} else {
m_stopFactor = m_currentFactNumber - 1;
}

View file

@ -27,12 +27,12 @@ class FactorizationController : public QObject {
Q_PROPERTY(int iterationsPerCycle READ iterationsPerCycle WRITE setIterationsPerCycle NOTIFY iterationsPerCycleChanged)
Q_PROPERTY(bool useSqrtOptimization READ useSqrtOptimization WRITE setUseSqrtOptimization NOTIFY useSqrtOptimizationChanged)
Q_PROPERTY(bool pauseOnFound READ pauseOnFound WRITE setPauseOnFound NOTIFY pauseOnFoundChanged)
Q_PROPERTY(long long number READ number NOTIFY numberChanged)
Q_PROPERTY(long long curFactNumber READ curFactNumber NOTIFY curFactNumberChanged)
Q_PROPERTY(long long currentFactor READ currentFactor NOTIFY currentFactorChanged)
Q_PROPERTY(long long stopFactor READ stopFactor NOTIFY stopFactorChanged)
Q_PROPERTY(unsigned long long number READ number NOTIFY numberChanged)
Q_PROPERTY(unsigned long long curFactNumber READ curFactNumber NOTIFY curFactNumberChanged)
Q_PROPERTY(unsigned long long currentFactor READ currentFactor NOTIFY currentFactorChanged)
Q_PROPERTY(unsigned long long stopFactor READ stopFactor NOTIFY stopFactorChanged)
Q_PROPERTY(int progress READ progress NOTIFY progressChanged)
Q_PROPERTY(QList<long long> factors READ factors NOTIFY factorsChanged)
Q_PROPERTY(QList<unsigned long long> factors READ factors NOTIFY factorsChanged)
public:
explicit FactorizationController(QObject* parent = nullptr);
@ -99,7 +99,7 @@ class FactorizationController : public QObject {
* @brief Gets the original number being factorized.
* @return The number being factorized.
*/
long long number() const;
unsigned long long number() const;
/**
* @brief The current number being factorized.
@ -108,7 +108,7 @@ class FactorizationController : public QObject {
* As the factorization process is going on, the number being factorized might change
* from the original number, as we're dividing it by the found factors.
*/
long long curFactNumber() const;
unsigned long long curFactNumber() const;
/**
* @brief Gets the current factor being tested.
@ -118,7 +118,7 @@ class FactorizationController : public QObject {
* is a factor, going one by one. This returns the current factor (to be checked in the
* next iteration).
*/
long long currentFactor() const;
unsigned long long currentFactor() const;
/**
* @brief Get the number at which the factorization process will stop
@ -128,7 +128,7 @@ class FactorizationController : public QObject {
* If sqrt optimizations are enabled, this will generally be the square root of the number
* currently being factorized. If not, it will be the number being factorized - 1.
*/
long long stopFactor() const;
unsigned long long stopFactor() const;
/**
* @brief Gets the list of discovered factors (may not be complete).
@ -138,7 +138,7 @@ class FactorizationController : public QObject {
* be complete (if the computation is still running). If you need to know whether you
* can trust this result, check isFinished first.
*/
QList<long long> factors() const;
QList<unsigned long long> factors() const;
// endregion
// region: Setters
@ -189,7 +189,7 @@ class FactorizationController : public QObject {
* This will start a 0-tick timer, which triggers a partial computation on each run,
* to let the event loop cycle in between. This implementation does NOT rely on threads.
*/
Q_INVOKABLE void start(long long number);
Q_INVOKABLE void start(unsigned long long number);
/**
* @brief Stops the ongoing factorization process.
@ -241,11 +241,11 @@ class FactorizationController : public QObject {
bool m_useSqrtOptimization; ///< Indicates whether to use the sqrt optimization
bool m_pauseOnFound; ///< Indicates whether the computation should be paused when a new factor is found.
int m_iterationsPerCycle; ///< The number of iterations to perform per cycle.
long long m_currentFactNumber; ///< The number currently being factorized.
long long m_originalNumber; ///< The original input number.
long long m_currentFactor; ///< The current divisor being checked.
long long m_stopFactor; ///< The stopping limit (square root of original number, saved for efficiency).
QList<long long> m_factors; ///< List of discovered prime factors.
unsigned long long m_currentFactNumber; ///< The number currently being factorized.
unsigned long long m_originalNumber; ///< The original input number.
unsigned long long m_currentFactor; ///< The current divisor being checked.
unsigned long long m_stopFactor; ///< The stopping limit (square root of original number, saved for efficiency).
QList<unsigned long long> m_factors; ///< List of discovered prime factors.
QTimer m_timer; ///< Timer for stepwise execution.
/**