View | Details | Raw Unified | Return to bug 33375
Collapse All | Expand All

(-)src/java/org/apache/poi/hssf/model/FormulaParser.java (-1 / +7 lines)
Lines 484-490 Link Here
484
                if (IsDigit(look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
484
                if (IsDigit(look)) number = number +"."+ GetNum(); //this also takes care of someone entering "1234."
485
                tokens.add(new NumberPtg(number));
485
                tokens.add(new NumberPtg(number));
486
            } else {
486
            } else {
487
                tokens.add(new IntPtg(number));  //TODO:what if the number is too big to be a short? ..add factory to return Int or Number!
487
                long tempNum = Long.parseLong(number.trim());
488
                if (tempNum <= Short.MAX_VALUE && tempNum >= Short.MIN_VALUE) {
489
                    tokens.add(new IntPtg(number));
490
                }
491
                else {
492
                    tokens.add(new NumberPtg(number)); 
493
                }
488
            }
494
            }
489
        }
495
        }
490
    }
496
    }
(-)src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java (+12 lines)
Lines 23-28 Link Here
23
import org.apache.poi.hssf.record.formula.AddPtg;
23
import org.apache.poi.hssf.record.formula.AddPtg;
24
import org.apache.poi.hssf.record.formula.AttrPtg;
24
import org.apache.poi.hssf.record.formula.AttrPtg;
25
import org.apache.poi.hssf.record.formula.BoolPtg;
25
import org.apache.poi.hssf.record.formula.BoolPtg;
26
import org.apache.poi.hssf.record.formula.DividePtg;
26
import org.apache.poi.hssf.record.formula.EqualPtg;
27
import org.apache.poi.hssf.record.formula.EqualPtg;
27
import org.apache.poi.hssf.record.formula.FuncVarPtg;
28
import org.apache.poi.hssf.record.formula.FuncVarPtg;
28
import org.apache.poi.hssf.record.formula.IntPtg;
29
import org.apache.poi.hssf.record.formula.IntPtg;
Lines 30-35 Link Here
30
import org.apache.poi.hssf.record.formula.LessThanPtg;
31
import org.apache.poi.hssf.record.formula.LessThanPtg;
31
import org.apache.poi.hssf.record.formula.NamePtg;
32
import org.apache.poi.hssf.record.formula.NamePtg;
32
import org.apache.poi.hssf.record.formula.NotEqualPtg;
33
import org.apache.poi.hssf.record.formula.NotEqualPtg;
34
import org.apache.poi.hssf.record.formula.NumberPtg;
33
import org.apache.poi.hssf.record.formula.Ptg;
35
import org.apache.poi.hssf.record.formula.Ptg;
34
import org.apache.poi.hssf.record.formula.ReferencePtg;
36
import org.apache.poi.hssf.record.formula.ReferencePtg;
35
import org.apache.poi.hssf.record.formula.StringPtg;
37
import org.apache.poi.hssf.record.formula.StringPtg;
Lines 56-61 Link Here
56
        
58
        
57
    }
59
    }
58
    
60
    
61
    public void testSimpleLongFormula() {
62
        FormulaParser fp = new FormulaParser("40000/2", null);
63
        fp.parse();
64
        Ptg[] ptgs = fp.getRPNPtg();
65
        assertTrue("three tokens expected, got "+ptgs.length,ptgs.length == 3);
66
        assertTrue("",(ptgs[0] instanceof NumberPtg));
67
        assertTrue("",(ptgs[1] instanceof IntPtg));
68
        assertTrue("",(ptgs[2] instanceof DividePtg));
69
    }
70
    
59
    public void testSimpleFormula() {
71
    public void testSimpleFormula() {
60
        FormulaParser fp = new FormulaParser("2+2;",null);
72
        FormulaParser fp = new FormulaParser("2+2;",null);
61
        fp.parse();
73
        fp.parse();

Return to bug 33375