0

so i've made this function for printing big primes between the interval L,U:
1. This function runs correctly for small numbers.
2. When I try to print the primes between two big numbers(for example, 100000000 and 100100000),
on IDEONE.com, it says: runtime error signal:25
on linux(using terminal) it says: floating point exception (core dumped)

what might have gone wrong in this process of translation from small numbers to big numbers?

//primes[] stores all the primes between 2 and sqrt(1000000000)

    void check(long long L,long long U,long long primes[])
    {
        long long g=0,i=0,d;
        if(L==1)
        L++;
        long long v=sqrt(1000000000);
        for(long long k=L;k<U+1;k++)
        {
            i=0;
            d=sqrt(k);
            while(i<=v)     //this statement...
            {
                if(primes[i]<=d)
                {
                    if(k%primes[i]==0)
                    {g=1;break;}
                    ++i;
                }
                else
                break;
            }

            if(g==0)
            {
                cout<<k<<endl;
            }
            g=0;
        }
        return;
    }

EDIT: I solved the problem by eliminating the unused intervals from primes[] (check comments) from my calculations. This probably decreased the number of calculations by a lot (10x less calculations in the marked while statement.)Thanks to all those who responded.

pyroscepter
  • 205
  • 1
  • 3
  • 9
  • 1
    You have a debugger. Please try using it. And/Or Valgrid – Mitch Wheat Nov 27 '14 at 07:04
  • the debugger i'm using(the default debugger for orwell dev c++ on windows) shows nothing. i.e, when I run the debugger, it opens the original program, outputs some values from the interval, and then closes. The debugger never opens in this case. weird. (it, however, opens when I use it on any of my other programs.) – pyroscepter Nov 27 '14 at 07:18
  • What value are you passing to the function for "primes[]"? – Amadeus Nov 27 '14 at 07:18
  • i created an array primes of size sqrt(1000000000) and started filling primes in it from the beginning(1st element is 2, 2nd is 3, 3rd is 5 and so on.)(primes started from 2 till 31607). the rest of the space is unused. the primes are valid, and exhaustive within this range. – pyroscepter Nov 27 '14 at 07:28

1 Answers1

0

check signature of

double sqrt(double x)

what is the max value it can take.

Nihar
  • 347
  • 2
  • 16
  • I don't think there's any problem in the square root function. i've printed out sqrt(1000000000) and it gave the correct answer. all the numbers where i'm using this function, are less than the previous number. – pyroscepter Nov 27 '14 at 07:10