本文整理汇总了Java中java.lang.ArithmeticException类的典型用法代码示例。如果您正苦于以下问题:Java ArithmeticException类的具体用法?Java ArithmeticException怎么用?Java ArithmeticException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArithmeticException类属于java.lang包,在下文中一共展示了ArithmeticException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: castToInt
import java.lang.ArithmeticException; //导入依赖的package包/类
public static int castToInt(String s)
{
if (s == null)
return 0;
if (s.equals("INF") || s.equals("-INF") || s.equals("NaN"))
throw new ArithmeticException("'" + s + "' is too large for int.");
s = s.trim();
java.lang.StringBuffer buf = new java.lang.StringBuffer();
switch (prepareNumber(buf, s))
{
case 1:
return Integer.parseInt(buf.toString());
case 2:
return new BigDecimal(buf.toString()).intValue();
case 3:
return (int)Double.parseDouble(buf.toString());
default:
throw new NumberFormatException("'" + s + "' cannot be converted to int.");
}
}
示例2: castToLong
import java.lang.ArithmeticException; //导入依赖的package包/类
public static long castToLong(String s)
{
if (s == null)
return 0;
if (s.equals("INF") || s.equals("-INF") || s.equals("NaN"))
throw new ArithmeticException("'" + s + "' is too large for long.");
s = s.trim();
java.lang.StringBuffer buf = new java.lang.StringBuffer();
switch (prepareNumber(buf, s))
{
case 1:
return Long.parseLong(buf.toString());
case 2:
return new BigDecimal(buf.toString()).longValue();
case 3:
return (long)Double.parseDouble(buf.toString());
default:
throw new NumberFormatException("'" + s + "' cannot be converted to long.");
}
}
示例3: castToBigInteger
import java.lang.ArithmeticException; //导入依赖的package包/类
public static BigInteger castToBigInteger(String s)
{
if (s == null)
return null;
if (s.equals("INF") || s.equals("-INF") || s.equals("NaN"))
throw new ArithmeticException("'" + s + "' is too large for integer.");
s = s.trim();
java.lang.StringBuffer buf = new java.lang.StringBuffer();
switch (prepareNumber(buf, s))
{
case 1:
return new BigInteger(buf.toString());
case 2:
case 3:
return new BigDecimal(buf.toString()).toBigInteger();
default:
throw new NumberFormatException("'" + s + "' cannot be converted to integer.");
}
}
示例4: castToBigDecimal
import java.lang.ArithmeticException; //导入依赖的package包/类
public static BigDecimal castToBigDecimal(String s)
{
if (s == null)
return null;
if (s.equals("INF") || s.equals("-INF") || s.equals("NaN"))
throw new ArithmeticException("'" + s + "' is too large for decimal.");
s = s.trim();
java.lang.StringBuffer buf = new java.lang.StringBuffer();
switch (prepareNumber(buf, s))
{
case 1:
case 2:
case 3:
return new BigDecimal(buf.toString());
default:
throw new NumberFormatException("'" + s + "' cannot be converted to decimal.");
}
}
示例5: yn
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* Yn double.
*
* @param n integer order
* @param x a double value
* @return the Bessel function of the second kind, of order n of the argument.
* @throws ArithmeticException the arithmetic exception
*/
static public double yn(int n, double x) throws ArithmeticException {
double by,bym,byp,tox;
if(n == 0) return y0(x);
if(n == 1) return y1(x);
tox=2.0/x;
by=y1(x);
bym=y0(x);
for (int j=1;j<n;j++) {
byp=j*tox*by-bym;
bym=by;
by=byp;
}
return by;
}
示例6: normal
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* Normal double.
*
* @param a double value
* @return The area under the Gaussian probability density function, integrated from minus infinity to x:
* @throws ArithmeticException the arithmetic exception
*/
static public double normal( double a)
throws ArithmeticException {
double x, y, z;
x = a * SQRTH;
z = Math.abs(x);
if( z < SQRTH ) y = 0.5 + 0.5 * erf(x);
else {
y = 0.5 * erfc(z);
if( x > 0 ) y = 1.0 - y;
}
return y;
}
示例7: erf
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* Erf double.
*
* @param x the x
* @return The Error function Converted to Java from<BR> Cephes Math Library Release 2.2: July,
* 1992<BR> Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> Direct inquiries to 30 Frost Street,
* Cambridge, MA 02140<BR>
* @throws ArithmeticException the arithmetic exception
*/
static public double erf(double x)
throws ArithmeticException {
double y, z;
double T[] = {
9.60497373987051638749E0,
9.00260197203842689217E1,
2.23200534594684319226E3,
7.00332514112805075473E3,
5.55923013010394962768E4
};
double U[] = {
//1.00000000000000000000E0,
3.35617141647503099647E1,
5.21357949780152679795E2,
4.59432382970980127987E3,
2.26290000613890934246E4,
4.92673942608635921086E4
};
if( Math.abs(x) > 1.0 ) return( 1.0 - erfc(x) );
z = x * x;
y = x * polevl( z, T, 4 ) / p1evl( z, U, 5 );
return y;
}
示例8: yn
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param n integer order
* @param x a double value
* @return the Bessel function of the second kind,
* of order n of the argument.
*/
static public double yn(int n, double x) throws ArithmeticException {
double by,bym,byp,tox;
if(n == 0) return y0(x);
if(n == 1) return y1(x);
tox=2.0/x;
by=y1(x);
bym=y0(x);
for (int j=1;j<n;j++) {
byp=j*tox*by-bym;
bym=by;
by=byp;
}
return by;
}
示例9: stirf
import java.lang.ArithmeticException; //导入依赖的package包/类
static private double stirf(double x) throws ArithmeticException {
double STIR[] = {
7.87311395793093628397E-4,
-2.29549961613378126380E-4,
-2.68132617805781232825E-3,
3.47222221605458667310E-3,
8.33333333333482257126E-2,
};
double MAXSTIR = 143.01608;
double w = 1.0/x;
double y = Math.exp(x);
w = 1.0 + w * polevl( w, STIR, 4 );
if( x > MAXSTIR ) {
/* Avoid overflow in Math.pow() */
double v = Math.pow( x, 0.5 * x - 0.25 );
y = v * (v / y);
} else {
y = Math.pow( x, x - 0.5 ) / y;
}
y = SQTPI * y * w;
return y;
}
示例10: normal
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param a double value
* @return The area under the Gaussian probability density
* function, integrated from minus infinity to x:
*/
static public double normal( double a)
throws ArithmeticException {
double x, y, z;
x = a * SQRTH;
z = Math.abs(x);
if( z < SQRTH ) y = 0.5 + 0.5 * erf(x);
else {
y = 0.5 * erfc(z);
if( x > 0 ) y = 1.0 - y;
}
return y;
}
示例11: erf
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param a double value
* @return The Error function
* <P>
* <FONT size=2>
* Converted to Java from<BR>
* Cephes Math Library Release 2.2: July, 1992<BR>
* Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR>
* Direct inquiries to 30 Frost Street, Cambridge, MA 02140<BR>
*/
static public double erf(double x)
throws ArithmeticException {
double y, z;
double T[] = {
9.60497373987051638749E0,
9.00260197203842689217E1,
2.23200534594684319226E3,
7.00332514112805075473E3,
5.55923013010394962768E4
};
double U[] = {
//1.00000000000000000000E0,
3.35617141647503099647E1,
5.21357949780152679795E2,
4.59432382970980127987E3,
2.26290000613890934246E4,
4.92673942608635921086E4
};
if( Math.abs(x) > 1.0 ) return( 1.0 - erfc(x) );
z = x * x;
y = x * polevl( z, T, 4 ) / p1evl( z, U, 5 );
return y;
}
示例12: sinh
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param x a double value
* @return the hyperbolic sine of the argument
*
* @throws ArithmeticException
*/
static public double sinh(double x) throws ArithmeticException {
double a;
if (x == 0.0) {
return x;
}
a = x;
if (a < 0.0) {
a = Math.abs(x);
}
a = Math.exp(a);
if (x < 0.0) {
return -0.5 * (a - 1 / a);
} else {
return 0.5 * (a - 1 / a);
}
}
示例13: tanh
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param x a double value
* @return the hyperbolic tangent of the argument
*
* @throws ArithmeticException
*/
static public double tanh(double x) throws ArithmeticException {
double a;
if (x == 0.0) {
return x;
}
a = x;
if (a < 0.0) {
a = Math.abs(x);
}
a = Math.exp(2.0 * a);
if (x < 0.0) {
return -(1.0 - 2.0 / (a + 1.0));
} else {
return (1.0 - 2.0 / (a + 1.0));
}
}
示例14: asinh
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* Compute the hyperbolic arc sine
*
* @param xx a double value
*
* @return the hyperbolic arc sine of the argument
*
* @throws ArithmeticException
*/
static public double asinh(double xx) throws ArithmeticException {
double x;
int sign;
if (xx == 0.0) {
return xx;
}
if (xx < 0.0) {
sign = -1;
x = -xx;
} else {
sign = 1;
x = xx;
}
return sign * Math.log(x + Math.sqrt(x * x + 1));
}
示例15: yn
import java.lang.ArithmeticException; //导入依赖的package包/类
/**
* @param n integer order
* @param x a double value
* @return the Bessel function of the second kind,
* of order n of the argument.
*
* @throws ArithmeticException
*/
static public double yn(int n, double x) throws ArithmeticException {
double by, bym, byp, tox;
if (n == 0) {
return y0(x);
}
if (n == 1) {
return y1(x);
}
tox = 2.0 / x;
by = y1(x);
bym = y0(x);
for (int j = 1; j < n; j++) {
byp = j * tox * by - bym;
bym = by;
by = byp;
}
return by;
}