Floating point exception

I'm assuming that you lot know much better than I do with this, so what does the error "Floating point exception" mean?

By the way, my long answer to Question 7 of Project Euler is here. If you do not want to be spoiled at all, please don't look. Though, my usual solutions are completely wrong with Project Euler.







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <valarray>
#include <cmath>

using std::valarray;




int main() {
        int Ar_Size = 6;
        int Or_Size = 5;

        int PRIMES[] = {2, 3, 5, 7, 9, 13};
        int O_PRIMES[] = {3, 5, 7, 9, 13};
        valarray<int> P_Arr(PRIMES, Ar_Size);
        valarray<int>p(O_PRIMES , Or_Size);

        int i;
        double n = 13.0;
        int a;
        bool PRI;
        double temp = 13.0;
        int rep;
        for(i = 6; i < 10001; i++){     /*For the array.*/
                for(n = temp; ;n++){    /*Search through the numbers*/
                        double sq = sqrt(n);
                        rep = (int)n;
                        for(a = 0; a < (int)sq; a++){   /*Making sure the numbers are primes*/
                                if((rep % 2) == 0)
                                        break;
                                else if((rep % P_Arr[a]) == 0)
                                        break;
                                else
                                        temp = n;
                                        Ar_Size++;
                                        P_Arr.resize(Ar_Size);
                                        P_Arr[Ar_Size - 1] = rep;
                                        if((rep % 3) != 0){ 
                                                Or_Size++;
                                                p.resize(Or_Size);
                                                p[Or_Size - 1] = rep;

                                        }
                                        PRI = true;

                        }

                        if(PRI == true)
                                break;
                        else
                                continue;
                }

                PRI = false;
        }


        std::cout << P_Arr.max() << '\n';


        return 0;
}
A little off-topic, but this is a really complicated way of doing this problem. Nothing from <cmath> is required (or valarray).
This is what happens when you try to use 0 in the modulus operator:

rep % P_Arr[a]

P_Arr(a) is zero.

This exception would be better named "arithmetic exception", but the name it has sticks for backwards-compatibility.
Topic archived. No new replies allowed.