私は大きな数の素因数分解に取り組んでいます (主にproject 3 @ project Euler . long long として宣言された数値にモジュラスを使用する必要があります。その巨大な数をモジュラスしようとするたびに、浮動小数点例外が発生します。感謝します。
これを gdb で実行して、何が起こっているかを確認しました。以下は私のコードです。この時点では非常に大雑把な論理です。 私 に 問題 の 答え を 教え ない で ください. これをより良くするための助けを喜んで受け入れますが、率直な答えを私に与えないでください. ありがとう :)
long factor(long number) {
string br = "\n\r";
long x = 0;
/*this modulus variable is an attempt
to move the answer into a long long container
to see if that solves my floating point exception,
it didn't*/
long long modulus;
while(x <= number) {
modulus = number % x;
if(modulus == 0) {
cout << number/x << br;
return factor(number/x);
}//if number % x
else {
return x;
}//else
x++;
}//while
}//factor