Package org.jruby

Examples of org.jruby.RubyRational


    private static RubyBigDecimal getVpValue19(ThreadContext context, IRubyObject v, boolean must) {
        return getVpValueWithPrec19(context, v, -1, must);
    }
   
    private static IRubyObject getVpRubyObjectWithPrec19Inner(ThreadContext context, RubyRational r, long precision, boolean must) {
        RubyRational orig = null;
        IRubyObject numerator = null;
        while (true) {
            IRubyObject value;
            boolean div;
            if (orig == null) {
View Full Code Here


                        if (context.getPrecision() > RubyFloat.DIG + 1) {
                            throw runtime.newArgumentError("precision too large");
                        }
                        return new RubyBigDecimal(runtime, (RubyClass)recv, new BigDecimal(((RubyFloat)args[0]).getDoubleValue(), context));
                    } else {
                        RubyRational rat = (RubyRational)args[0];

                        BigDecimal num = new BigDecimal(rat.numerator(ctx).convertToInteger().getLongValue());
                        BigDecimal den = new BigDecimal(rat.denominator(ctx).convertToInteger().getLongValue());

                        BigDecimal value = num.divide(den, context);

                        return new RubyBigDecimal(runtime, value);
                    }
View Full Code Here

        runtime = Ruby.newInstance();
    }

    // JRUBY-5941
    public void testRationalToDouble() throws Exception {
        RubyRational rational = RubyRational.newRational(runtime, 1, 1000);
        double toDouble = rational.getDoubleValue();
        double expected = ((RubyFloat)rational.to_f(runtime.getCurrentContext())).getDoubleValue();
        assertEquals(expected, toDouble);
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyRational

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.