File tree Expand file tree Collapse file tree
main/java/org/apache/datasketches/common
test/java/org/apache/datasketches/common Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -445,13 +445,15 @@ public static long ceilingMultiple2expK(final long n, final int k) {
445445 }
446446
447447 /**
448- * Computes the inverse integer power of 2: 1/(2^e ) = 2^(-e ).
449- * @param e a positive value between 0 and 1023 inclusive
450- * @return the inverse integer power of 2: 1/(2^e ) = 2^(-e )
448+ * Computes the inverse integer power of 2: 1/(2^exp ) = 2^(-exp ).
449+ * @param exp a positive value between 0 and 1023 inclusive
450+ * @return the inverse integer power of 2: 1/(2^exp ) = 2^(-exp )
451451 */
452- public static double invPow2 (final int e ) {
453- assert (e | (1024 - e - 1 )) >= 0 : "e cannot be negative or greater than 1023: " + e ;
454- return Double .longBitsToDouble ((1023L - e ) << 52 );
452+ public static double invPow2 (final int exp ) {
453+ if ((exp | (1024 - exp - 1 )) < 0 ) {
454+ throw new SketchesArgumentException ("exp cannot be negative or greater than 1023: " + exp );
455+ }
456+ return Double .longBitsToDouble ((1023L - exp ) << 52 );
455457 }
456458
457459 /**
Original file line number Diff line number Diff line change @@ -203,9 +203,9 @@ public void checkIsMultipleOf8AndGT0() {
203203 public void checkInvPow2 () {
204204 Assert .assertEquals (invPow2 (1 ), 0.5 );
205205 Assert .assertEquals (invPow2 (0 ), 1.0 );
206- try { invPow2 (-1 ); failIAE (); } catch (final AssertionError e ) {}
207- try {invPow2 (1024 ); failIAE (); } catch (final AssertionError e ) {}
208- try {invPow2 (Integer .MIN_VALUE ); failIAE (); } catch (final AssertionError e ) {}
206+ try {invPow2 (-1 ); failIAE (); } catch (final SketchesArgumentException e ) {}
207+ try {invPow2 (1024 ); failIAE (); } catch (final SketchesArgumentException e ) {}
208+ try {invPow2 (Integer .MIN_VALUE ); failIAE (); } catch (final SketchesArgumentException e ) {}
209209 }
210210
211211 private static void failIAE () { throw new IllegalArgumentException ("Test should have failed!" ); }
You can’t perform that action at this time.
0 commit comments