Here you can find the source of isprime(double x)
public static double isprime(double x)
//package com.java2s; /** This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. *//*from ww w .j av a2s . co m*/ import java.text.*; import java.math.*; public class Main { public static double isprime(double x) { if ((Math.round(x) != toFix(x, 12)) || (x < 2)) { throw new IllegalArgumentException("isPrime(n), where n >= 2 is an integer"); } else { long n = Math.round(x); for (long i = 2; i <= Math.sqrt(n); i++) { double factor = n * 1.0 / i; if (Math.round(factor) == toFix(factor, 12)) return 0; } return 1; } } public static double toFix(double x, int dp) { String format = ""; for (int i = 0; i < dp; i++) { format = format + "#"; } return Double.parseDouble((new DecimalFormat("#0." + format)).format(x)); } public static String toFix(BigDecimal x, int dp) { String format = ""; for (int i = 0; i < dp; i++) { format = format + "#"; } return (new DecimalFormat("#0." + format)).format(x); } }