29
Mar
inline bool isprime()
Related Blog Items
- where to place inline keyword, in definition or declaration?
- Do inline functions improve performance?
- Using the auto_ptr concept in C++
- How can inline functions help with the tradeoff of safety vs. speed?
- Inline functions & Macros comparision
This is one of the more simple snippets I could actually write, and one of the best memorized pieces of code that I can actually write as the starting post of this blog. For interested bloggers who would want to be able to post their snippets here, contact me (Dean Michael Berris) through email (see page description for updated email information).
inline bool isprime(unsigned long int number)
{
if (number <= 3)
return true;
if ((number % 2) == 0)
return false;
for (unsigned register int i = 5; i * i <= number; i+=2)
{
if ((number % i) == 0)
return false;
}
return true;
}
Comments and optimizations most welcome.
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Popularity: 5%
You need to log on to convert this article into PDF
Related Blog Items - where to place inline keyword, in definition or declaration?
- Do inline functions improve performance?
- Using the auto_ptr concept in C++
- How can inline functions help with the tradeoff of safety vs. speed?
- Inline functions & Macros comparision
Related Blog Items
- where to place inline keyword, in definition or declaration?
- Do inline functions improve performance?
- Using the auto_ptr concept in C++
- How can inline functions help with the tradeoff of safety vs. speed?
- Inline functions & Macros comparision
in the loop,
you don’t need to check until the number itself..checking until the square root of that number is enough…
for (unsigned register int i = 5; i * i
April 17th, 2007 at 8:58 am
for (unsigned register int i = 5; i * i
April 17th, 2007 at 8:59 am