Logo Search packages:      
Sourcecode: kbruch version File versions  Download package

void primenumber::find_next (  ) [private]

finds next prime number and adds it to the vector

Definition at line 166 of file primenumber.cpp.

References current_pos, and prim_vector.

Referenced by get_next(), and move_forward().

{
    /* our new prime number, must be bigger than the last one */
    unsigned int new_prim = * (prim_vector.end() - 1);

    do {
        /* new prime number must be bigger as biggest known one */
        new_prim += 2;
        /* loop as long as we find a divisor for the new number */
        for (current_pos = prim_vector.begin(); current_pos != prim_vector.end();
                ++current_pos)
            if ( (new_prim % *current_pos == 0) || (new_prim < *current_pos))
                break;

        /* if we tried all known numbers and found no divisor, well,
         * we are happy to have found a new prime number
         *
         * we found a prime number, because we only have to test the given
         * number against all known prime numbers smaller square root of the
         * number */
        if ( (current_pos == prim_vector.end())
                || (*current_pos * *current_pos > new_prim))
            break;
    } while (1);

    /* add the new prime number to the vector */
    prim_vector.push_back (new_prim);

    current_pos = prim_vector.end() - 1;
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index