]> source.dussan.org Git - poi.git/commitdiff
[bug-62738] make int cast a long cast in randbetween
authorPJ Fanning <fanningpj@apache.org>
Wed, 19 Sep 2018 12:18:56 +0000 (12:18 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 19 Sep 2018 12:18:56 +0000 (12:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1841321 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/atp/RandBetween.java
src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java

index 5eac08fe564009e7b4d8f5f85610f00897cc7c91..79f1c0acea6679455111efcffbe75a7655556992 100644 (file)
@@ -77,7 +77,7 @@ final class RandBetween implements FreeRefFunction{
                        top = bottom;
                }
                
-               return new NumberEval((bottom + (int)(Math.random() * ((top - bottom) + 1))));
+               return new NumberEval((bottom + (long)(Math.random() * ((top - bottom) + 1))));
                
        }
                
index 802b7d8b33176c3498aa451b506c74864bb88316..206d17016dcd32b1ca23121585109ce3bd1dd4b9 100644 (file)
@@ -53,12 +53,6 @@ public class TestRandBetween extends TestCase {
                formulaCell = row.createCell(2, CellType.FORMULA);
        }
        
-       @Override
-       protected void tearDown() throws Exception {
-               // TODO Auto-generated method stub
-               super.tearDown();
-       }
-       
        /**
         * Check where values are the same
         */
@@ -74,6 +68,17 @@ public class TestRandBetween extends TestCase {
                assertEquals(-1, formulaCell.getNumericCellValue(), 0);
 
        }
+
+       public void testRandBetweenLargeLongs() {
+        for (int i = 0; i < 100; i++) {
+            evaluator.clearAllCachedResultValues();
+            formulaCell.setCellFormula("RANDBETWEEN(0,9999999999)");
+            evaluator.evaluateFormulaCell(formulaCell);
+            double value = formulaCell.getNumericCellValue();
+            assertTrue("rand is greater than or equal to lowerbound", value >= 0.0);
+            assertTrue("rand is less than or equal to upperbound", value <= 9999999999.0);
+        }
+       }
        
        /**
         * Check special case where rounded up bottom value is greater than