private int getIntegerToken(String value, int radix, int suffix) { Node literalValue; if ((suffix & SUFFIX_R) != 0) { literalValue = newRationalNode(value, radix); } else { try { literalValue = newFixnumNode(value, radix); } catch (NumberFormatException e) { literalValue = newBignumNode(value, radix); } } yaccValue = literalValue; return considerComplex(RubyParser.tINTEGER, suffix); }
private int getIntegerToken(String value, int radix, int suffix) { Node literalValue; if ((suffix & SUFFIX_R) != 0) { literalValue = newRationalNode(value, radix); } else { try { literalValue = newFixnumNode(value, radix); } catch (NumberFormatException e) { literalValue = newBignumNode(value, radix); } } yaccValue = literalValue; return considerComplex(RubyParser.tINTEGER, suffix); }
private int getFloatToken(String number, int suffix) { if ((suffix & SUFFIX_R) != 0) { BigDecimal bd = new BigDecimal(number); BigDecimal denominator = BigDecimal.ONE.scaleByPowerOfTen(bd.scale()); BigDecimal numerator = bd.multiply(denominator); try { yaccValue = new RationalNode(getPosition(), new FixnumNode(getPosition(), numerator.longValueExact()), new FixnumNode(getPosition(), denominator.longValueExact())); } catch (ArithmeticException ae) { // FIXME: Rational supports Bignum numerator and denominator compile_error(PID.RATIONAL_OUT_OF_RANGE, "Rational (" + numerator + "/" + denominator + ") out of range."); } return considerComplex(RubyParser.tRATIONAL, suffix); } double d; try { d = SafeDoubleParser.parseDouble(number); } catch (NumberFormatException e) { warnings.warn(ID.FLOAT_OUT_OF_RANGE, getFile(), ruby_sourceline, "Float " + number + " out of range."); d = number.startsWith("-") ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } yaccValue = new FloatNode(getPosition(), d); return considerComplex(RubyParser.tFLOAT, suffix); }
private int getFloatToken(String number, int suffix) { if ((suffix & SUFFIX_R) != 0) { BigDecimal bd = new BigDecimal(number); BigDecimal denominator = BigDecimal.ONE.scaleByPowerOfTen(bd.scale()); BigDecimal numerator = bd.multiply(denominator); try { yaccValue = new RationalNode(getPosition(), new FixnumNode(getPosition(), numerator.longValueExact()), new FixnumNode(getPosition(), denominator.longValueExact())); } catch (ArithmeticException ae) { // FIXME: Rational supports Bignum numerator and denominator compile_error(PID.RATIONAL_OUT_OF_RANGE, "Rational (" + numerator + "/" + denominator + ") out of range."); } return considerComplex(RubyParser.tRATIONAL, suffix); } double d; try { d = SafeDoubleParser.parseDouble(number); } catch (NumberFormatException e) { warnings.warn(ID.FLOAT_OUT_OF_RANGE, getFile(), ruby_sourceline, "Float " + number + " out of range."); d = number.startsWith("-") ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY; } yaccValue = new FloatNode(getPosition(), d); return considerComplex(RubyParser.tFLOAT, suffix); }