4 replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/ edited Apr 13 '17 at 12:40 Is there such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect is a tad faster but, more importantly, easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2): http://codereview.stackexchange.com/a/7342/507https://codereview.stackexchange.com/a/7342/507 Is there such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect is a tad faster but, more importantly, easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2): http://codereview.stackexchange.com/a/7342/507 Is there such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect is a tad faster but, more importantly, easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2): https://codereview.stackexchange.com/a/7342/507 3 improved formatting, fixed typos edit approved Feb 6 '12 at 4:14 seand 2,44511 gold badge1414 silver badges2929 bronze badges Is theirthere such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use %% rather than fmod()fmod() which I would suspect idis a tad faster nutbut, more importantly, easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 33 as well as 22):    http://codereview.stackexchange.com/a/7342/507 Is their such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect id a tad faster nut more importantly easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2):  http://codereview.stackexchange.com/a/7342/507 Is there such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect is a tad faster but, more importantly, easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2):  http://codereview.stackexchange.com/a/7342/507 2 added 337 characters in body edited Feb 4 '12 at 22:28 Martin York 76.9k44 gold badges9292 silver badges287287 bronze badges Is their such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect id a tad faster nut more importantly easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2): http://codereview.stackexchange.com/a/7342/507 Is their such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect id a tad faster nut more importantly easier to read. Here is a link to cool but not obvious optimization: http://codereview.stackexchange.com/a/7342/507 Is their such a thing as a prime real number? If not then the function signature should use integer (preferably unsigned as there are no negative primes). Then you should be able to use % rather than fmod() which I would suspect id a tad faster nut more importantly easier to read. Since you have already checked for all even primes: for (int i = 3; i < sqrt(value); i+=2) { // ^^^^ No need to increment by 1; // All evens already checked already so inc by 2 // So just check 3/5/7/9 etc  Here is a link to cool but not obvious optimization (That allows you to avoid checking all multiples of 3 as well as 2): http://codereview.stackexchange.com/a/7342/507 1 answered Feb 4 '12 at 22:23 Martin York 76.9k44 gold badges9292 silver badges287287 bronze badges