summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-06-19 18:27:45 -0700
committerHans Boehm <hboehm@google.com>2015-06-19 18:27:45 -0700
commit9666c57ab247046b716e9c1e56f0dcc7d4a1545f (patch)
tree28451941ca538fe7475f474b5e9715a90a70a8f1
parentb849a8eb275670d2bd9b2dc535231cf333414f5e (diff)
downloadcrcalc-nougat-mr2-release.tar.gz
Replace errors by unchecked exceptionsandroid-n-preview-1android-cts_7.1_r1android-cts-7.1_r9android-cts-7.1_r8android-cts-7.1_r7android-cts-7.1_r6android-cts-7.1_r5android-cts-7.1_r4android-cts-7.1_r3android-cts-7.1_r29android-cts-7.1_r28android-cts-7.1_r27android-cts-7.1_r26android-cts-7.1_r25android-cts-7.1_r24android-cts-7.1_r23android-cts-7.1_r22android-cts-7.1_r21android-cts-7.1_r20android-cts-7.1_r2android-cts-7.1_r19android-cts-7.1_r18android-cts-7.1_r17android-cts-7.1_r16android-cts-7.1_r15android-cts-7.1_r14android-cts-7.1_r13android-cts-7.1_r12android-cts-7.1_r11android-cts-7.1_r10android-cts-7.1_r1android-cts-7.0_r9android-cts-7.0_r8android-cts-7.0_r7android-cts-7.0_r6android-cts-7.0_r5android-cts-7.0_r4android-cts-7.0_r33android-cts-7.0_r32android-cts-7.0_r31android-cts-7.0_r30android-cts-7.0_r3android-cts-7.0_r29android-cts-7.0_r28android-cts-7.0_r27android-cts-7.0_r26android-cts-7.0_r25android-cts-7.0_r24android-cts-7.0_r23android-cts-7.0_r22android-cts-7.0_r21android-cts-7.0_r20android-cts-7.0_r2android-cts-7.0_r19android-cts-7.0_r18android-cts-7.0_r17android-cts-7.0_r16android-cts-7.0_r15android-cts-7.0_r14android-cts-7.0_r13android-cts-7.0_r12android-cts-7.0_r11android-cts-7.0_r10android-cts-7.0_r1android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-7.1.1_r9android-7.1.1_r8android-7.1.1_r7android-7.1.1_r61android-7.1.1_r60android-7.1.1_r6android-7.1.1_r59android-7.1.1_r58android-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r54android-7.1.1_r53android-7.1.1_r52android-7.1.1_r51android-7.1.1_r50android-7.1.1_r49android-7.1.1_r48android-7.1.1_r47android-7.1.1_r46android-7.1.1_r45android-7.1.1_r44android-7.1.1_r43android-7.1.1_r42android-7.1.1_r41android-7.1.1_r40android-7.1.1_r4android-7.1.1_r39android-7.1.1_r38android-7.1.1_r35android-7.1.1_r33android-7.1.1_r32android-7.1.1_r31android-7.1.1_r3android-7.1.1_r28android-7.1.1_r27android-7.1.1_r26android-7.1.1_r25android-7.1.1_r24android-7.1.1_r23android-7.1.1_r22android-7.1.1_r21android-7.1.1_r20android-7.1.1_r2android-7.1.1_r17android-7.1.1_r16android-7.1.1_r15android-7.1.1_r14android-7.1.1_r13android-7.1.1_r12android-7.1.1_r11android-7.1.1_r10android-7.1.1_r1android-7.1.0_r7android-7.1.0_r6android-7.1.0_r5android-7.1.0_r4android-7.1.0_r3android-7.1.0_r2android-7.1.0_r1android-7.0.0_r9android-7.0.0_r8android-7.0.0_r7android-7.0.0_r6android-7.0.0_r5android-7.0.0_r4android-7.0.0_r36android-7.0.0_r35android-7.0.0_r34android-7.0.0_r33android-7.0.0_r32android-7.0.0_r31android-7.0.0_r30android-7.0.0_r3android-7.0.0_r29android-7.0.0_r28android-7.0.0_r27android-7.0.0_r24android-7.0.0_r21android-7.0.0_r19android-7.0.0_r17android-7.0.0_r15android-7.0.0_r14android-7.0.0_r13android-7.0.0_r12android-7.0.0_r11android-7.0.0_r10android-7.0.0_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1nougat-releasenougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-mr1.8-releasenougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-releasenougat-mr1.4-releasenougat-mr1.3-releasenougat-mr1.2-releasenougat-mr1.1-releasenougat-mr1-volantis-releasenougat-mr1-security-releasenougat-mr1-releasenougat-mr1-flounder-releasenougat-mr1-devnougat-mr1-cts-releasenougat-mr0.5-releasenougat-dr1-releasenougat-devnougat-cts-releasenougat-bugfix-releasemarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-release
Bug: 20667245 Also makes the exception classes local to CR, consistent with 21st century programming style. Change-Id: Iea7956715d8942fa87c6cd68fb6a9ca11ea73b89
-rw-r--r--src/com/hp/creals/AbortedError.java50
-rw-r--r--src/com/hp/creals/CR.java45
-rw-r--r--src/com/hp/creals/PrecisionOverflowError.java52
-rw-r--r--src/com/hp/creals/UnaryCRFunction.java4
4 files changed, 36 insertions, 115 deletions
diff --git a/src/com/hp/creals/AbortedError.java b/src/com/hp/creals/AbortedError.java
deleted file mode 100644
index 1468805..0000000
--- a/src/com/hp/creals/AbortedError.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (c) 1999, Silicon Graphics, Inc. -- ALL RIGHTS RESERVED
-//
-// Permission is granted free of charge to copy, modify, use and distribute
-// this software provided you include the entirety of this notice in all
-// copies made.
-//
-// THIS SOFTWARE IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY
-// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
-// WARRANTIES THAT THE SUBJECT SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT
-// FOR A PARTICULAR PURPOSE OR NON-INFRINGING. SGI ASSUMES NO RISK AS TO THE
-// QUALITY AND PERFORMANCE OF THE SOFTWARE. SHOULD THE SOFTWARE PROVE
-// DEFECTIVE IN ANY RESPECT, SGI ASSUMES NO COST OR LIABILITY FOR ANY
-// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES
-// AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY SUBJECT SOFTWARE IS
-// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
-//
-// UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING,
-// WITHOUT LIMITATION, NEGLIGENCE OR STRICT LIABILITY), CONTRACT, OR
-// OTHERWISE, SHALL SGI BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
-// INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WITH RESPECT TO THE
-// SOFTWARE INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK
-// STOPPAGE, LOSS OF DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL
-// OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SGI SHALL HAVE BEEN INFORMED OF
-// THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT
-// APPLY TO LIABILITY RESULTING FROM SGI's NEGLIGENCE TO THE EXTENT APPLICABLE
-// LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
-// EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
-// EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
-//
-// These license terms shall be governed by and construed in accordance with
-// the laws of the United States and the State of California as applied to
-// agreements entered into and to be performed entirely within California
-// between California residents. Any litigation relating to these license
-// terms shall be subject to the exclusive jurisdiction of the Federal Courts
-// of the Northern District of California (or, absent subject matter
-// jurisdiction in such courts, the courts of the State of California), with
-// venue lying exclusively in Santa Clara County, California.
-
-package com.hp.creals;
-
-/**
-* Indicates a constructive real operation was interrupted.
-* Most constructive real operations may throw such an error.
-* This is an error, since Number methods may not raise such
-* exceptions.
-*/
-public class AbortedError extends Error {
- public AbortedError() { super(); }
- public AbortedError(String s) { super(s); }
-}
diff --git a/src/com/hp/creals/CR.java b/src/com/hp/creals/CR.java
index 3812f90..dba2597 100644
--- a/src/com/hp/creals/CR.java
+++ b/src/com/hp/creals/CR.java
@@ -151,11 +151,11 @@ import java.math.BigInteger;
* provides the same functionality, but adds the caching necessary to obtain
* reasonable performance.
* <P>
-* Any operation may throw <TT>com.hp.creals.AbortedError</tt> if the thread in
+* Any operation may throw <TT>com.hp.creals.AbortedException</tt> if the thread in
* which it is executing is interrupted. (<TT>InterruptedException</tt> cannot
* be used for this purpose, since CR inherits from <TT>Number</tt>.)
* <P>
-* Any operation may also throw <TT>com.hp.creals.PrecisionOverflowError</tt>
+* Any operation may also throw <TT>com.hp.creals.PrecisionOverflowException</tt>
* If the precision request generated during any subcalculation overflows
* a 28-bit integer. (This should be extremely unlikely, except as an
* outcome of a division by zero, or other erroneous computation.)
@@ -168,6 +168,29 @@ public abstract class CR extends Number {
// We could do without the latter, but that would
// be atrociously slow.
+/**
+ * Indicates a constructive real operation was interrupted.
+ * Most constructive real operations may throw such an exception.
+ * This is unchecked, since Number methods may not raise checked
+ * exceptions.
+*/
+public static class AbortedException extends RuntimeException {
+ public AbortedException() { super(); }
+ public AbortedException(String s) { super(s); }
+}
+
+/**
+ * Indicates that the number of bits of precision requested by
+ * a computation on constructive reals required more than 28 bits,
+ * and was thus in danger of overflowing an int.
+ * This is likely to be a symptom of a diverging computation,
+ * <I>e.g.</i> division by zero.
+*/
+public static class PrecisionOverflowException extends RuntimeException {
+ public PrecisionOverflowException() { super(); }
+ public PrecisionOverflowException(String s) { super(s); }
+}
+
// First some frequently used constants, so we don't have to
// recompute these all over the place.
static final BigInteger big0 = BigInteger.ZERO;
@@ -183,7 +206,7 @@ public abstract class CR extends Number {
/**
* Setting this to true requests that all computations be aborted by
-* throwing AbortedError. Must be rest to false before any further
+* throwing AbortedException. Must be rest to false before any further
* computation. Ideally Thread.interrupt() should be used instead, but
* that doesn't appear to be consistently supported by browser VMs.
*/
@@ -229,7 +252,7 @@ public volatile static boolean please_stop = false;
// that should be as cheap as possible.
int high_shifted = n >> 29;
if (0 != (high ^ high_shifted)) {
- throw new PrecisionOverflowError();
+ throw new PrecisionOverflowException();
}
}
@@ -376,7 +399,7 @@ public volatile static boolean please_stop = false;
int msd = msd(prec);
if (msd != Integer.MIN_VALUE) return msd;
check_prec(prec);
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
}
return msd(n);
}
@@ -614,7 +637,7 @@ public volatile static boolean please_stop = false;
long long_msd_prec = (long)(log2_radix * (double)m);
if (long_msd_prec > (long)Integer.MAX_VALUE
|| long_msd_prec < (long)Integer.MIN_VALUE)
- throw new PrecisionOverflowError();
+ throw new PrecisionOverflowException();
int msd_prec = (int)long_msd_prec;
check_prec(msd_prec);
int msd = iter_msd(msd_prec - 2);
@@ -1196,7 +1219,7 @@ class prescaled_exp_CR extends CR {
BigInteger max_trunc_error =
big1.shiftLeft(p - 4 - calc_precision);
while (current_term.abs().compareTo(max_trunc_error) >= 0) {
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
n += 1;
/* current_term = current_term * op / n */
current_term = scale(current_term.multiply(op_appr), op_prec);
@@ -1239,7 +1262,7 @@ class prescaled_cos_CR extends slow_CR {
current_term = big1.shiftLeft(-calc_precision);
BigInteger current_sum = current_term;
while (current_term.abs().compareTo(max_trunc_error) >= 0) {
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
n += 2;
/* current_term = - current_term * op * op / n * (n - 1) */
current_term = scale(current_term.multiply(op_appr), op_prec);
@@ -1286,7 +1309,7 @@ class integral_atan_CR extends slow_CR {
BigInteger max_trunc_error =
big1.shiftLeft(p - 2 - calc_precision);
while (current_term.abs().compareTo(max_trunc_error) >= 0) {
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
n += 2;
current_power = current_power.divide(big_op_squared);
current_sign = -current_sign;
@@ -1331,7 +1354,7 @@ class prescaled_ln_CR extends slow_CR {
BigInteger max_trunc_error =
big1.shiftLeft(p - 4 - calc_precision);
while (current_term.abs().compareTo(max_trunc_error) >= 0) {
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
n += 1;
current_sign = -current_sign;
x_nth = scale(x_nth.multiply(op_appr), op_prec);
@@ -1396,7 +1419,7 @@ class prescaled_asin_CR extends slow_CR {
// before division by the exponent.
// Accurate to 3 ulp at calc_precision.
while (current_term.abs().compareTo(max_last_term) >= 0) {
- if (Thread.interrupted() || please_stop) throw new AbortedError();
+ if (Thread.interrupted() || please_stop) throw new AbortedException();
exp += 2;
// current_factor = current_factor * op * op * (exp-1) * (exp-2) /
// (exp-1) * (exp-1), with the two exp-1 factors cancelling,
diff --git a/src/com/hp/creals/PrecisionOverflowError.java b/src/com/hp/creals/PrecisionOverflowError.java
deleted file mode 100644
index f62e7f4..0000000
--- a/src/com/hp/creals/PrecisionOverflowError.java
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright (c) 1999, Silicon Graphics, Inc. -- ALL RIGHTS RESERVED
-//
-// Permission is granted free of charge to copy, modify, use and distribute
-// this software provided you include the entirety of this notice in all
-// copies made.
-//
-// THIS SOFTWARE IS PROVIDED ON AN AS IS BASIS, WITHOUT WARRANTY OF ANY
-// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
-// WARRANTIES THAT THE SUBJECT SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT
-// FOR A PARTICULAR PURPOSE OR NON-INFRINGING. SGI ASSUMES NO RISK AS TO THE
-// QUALITY AND PERFORMANCE OF THE SOFTWARE. SHOULD THE SOFTWARE PROVE
-// DEFECTIVE IN ANY RESPECT, SGI ASSUMES NO COST OR LIABILITY FOR ANY
-// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES
-// AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY SUBJECT SOFTWARE IS
-// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
-//
-// UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING,
-// WITHOUT LIMITATION, NEGLIGENCE OR STRICT LIABILITY), CONTRACT, OR
-// OTHERWISE, SHALL SGI BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
-// INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WITH RESPECT TO THE
-// SOFTWARE INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK
-// STOPPAGE, LOSS OF DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL
-// OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SGI SHALL HAVE BEEN INFORMED OF
-// THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT
-// APPLY TO LIABILITY RESULTING FROM SGI's NEGLIGENCE TO THE EXTENT APPLICABLE
-// LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
-// EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
-// EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
-//
-// These license terms shall be governed by and construed in accordance with
-// the laws of the United States and the State of California as applied to
-// agreements entered into and to be performed entirely within California
-// between California residents. Any litigation relating to these license
-// terms shall be subject to the exclusive jurisdiction of the Federal Courts
-// of the Northern District of California (or, absent subject matter
-// jurisdiction in such courts, the courts of the State of California), with
-// venue lying exclusively in Santa Clara County, California.
-
-package com.hp.creals;
-
-/**
-* Indicates that the number of bits of precision requested by
-* a computation on constructive reals required more than 28 bits,
-* and was thus in danger of overflowing an int.
-* This is likely to be a symptom of a diverging computation,
-* <I>e.g.</i> division by zero.
-*/
-public class PrecisionOverflowError extends Error {
- public PrecisionOverflowError() { super(); }
- public PrecisionOverflowError(String s) { super(s); }
-}
-
diff --git a/src/com/hp/creals/UnaryCRFunction.java b/src/com/hp/creals/UnaryCRFunction.java
index 60bf9c9..6f8ef5d 100644
--- a/src/com/hp/creals/UnaryCRFunction.java
+++ b/src/com/hp/creals/UnaryCRFunction.java
@@ -431,7 +431,7 @@ class inverseMonotone_UnaryCRFunction extends UnaryCRFunction {
BigInteger difference = h.subtract(l);
for(int i = 0;; ++i) {
if (Thread.interrupted() || please_stop)
- throw new AbortedError();
+ throw new AbortedException();
trace("***Iteration: " + i);
trace("Arg prec = " + working_arg_prec
+ " eval prec = " + working_eval_prec
@@ -653,7 +653,7 @@ class monotoneDerivative_UnaryCRFunction extends UnaryCRFunction {
return scale(appr_left_deriv, -extra_prec);
} else {
if (Thread.interrupted() || please_stop)
- throw new AbortedError();
+ throw new AbortedException();
deriv2_msd[0] =
eval_prec + deriv_difference.bitLength() + 4/*slop*/;
deriv2_msd[0] -= log_delta;