1 33 34 package edu.rice.cs.util.sexp; 35 36 public class NumberAtom implements Atom { 37 private double _num; 38 private boolean _hasDecimals; 39 public NumberAtom(int num){ 40 _num = (double)num; 41 _hasDecimals = false; 42 } 43 public NumberAtom(double num){ 44 _num = num; 45 _hasDecimals = (num % 1 < 1e-12); 46 } 47 public boolean hasDecimals() { return _hasDecimals; } 48 public int intValue() { return (int)_num; } 49 public double doubleValue() { return _num; } 50 51 56 public <Ret> Ret accept(SExpVisitor<Ret> v){ 57 return v.forNumberAtom(this); 58 } 59 60 public String toString(){ 61 if (_hasDecimals) { 62 return "" + doubleValue(); 63 } 64 else { 65 return "" + intValue(); 66 } 67 } 68 } | Popular Tags |