# CFLib.org – Common Function Library Project

##### Last updated November 21, 2001

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns True if the specified number is a prime number. A prime number is a positive integer that has two postive integer factors (the number is evenly divisible by 1 and itself). Note that 1 is not a prime number.

Return Values:
Returns a Boolean value

Example:

``````<cfset mynum = 11>
<cfset mynum2 = 15>

<cfoutput>
Given mynum = #mynum#<br>
Given mynum2 = #mynum2#<br>
</cfoutput>
``````

Parameters:

Name Description Required
inNum Any integer greater than one that you wish to test for prime. Yes

Full UDF Source:

``````/**
* Returns True if the specified number is a prime number.
* Minor edits by Rob Brooks-Bilson (rbils@amkor.com).  Edit by Steve Ford (steve.ford@enline.com) to fix misidentification of 4 as a prime number.  Algorithm improved by Shakti Shrivastava (divine_shammer@yahoo.com) -check up to sqr root of integer.  Further refined by Sierra Bufe (sierra@brighterfusion.com).
*
* @param inNum      Any integer greater than one that  you wish to test for prime.
* @return Returns a Boolean value
* @version 1.2, November 21, 2001
*/
{
var i=0;
if (inNum lt 2){
return False;
break;
}
for (i=2; i LTE (sqr(inNum)); i=i+1) {
if (NOT inNum MOD i) {
return False;
break;
}
}
return True;
}
``````

### Search CFLib.org

QueryDeleteRows
November 04, 2017

May 11, 2016