Package net.fortytwo.ripple.model

Examples of net.fortytwo.ripple.model.NumericValue


        }
    }

    // Note: does not check for divide-by-zero.
    public NumericValue mod(final NumericValue b) {
        NumericValue a = this;

        Type precision = maxPrecision(a, b);
        switch (precision) {
            case INTEGER:
                return new SesameNumericValue(a.intValue() % b.intValue());
            case LONG:
                return new SesameNumericValue(a.longValue() % b.longValue());
            case FLOAT:
                return new SesameNumericValue(a.floatValue() % b.floatValue());
            case DOUBLE:
                return new SesameNumericValue(a.doubleValue() % b.doubleValue());
            case DECIMAL:
                return new SesameNumericValue(a.decimalValue().remainder(b.decimalValue()).abs());
            default:
                // This shouldn't happen.
                return null;
        }
    }
View Full Code Here


                return null;
        }
    }

    public NumericValue pow(final NumericValue pow) {
        NumericValue a = this;

        if (Type.DECIMAL == a.getDatatype() && Type.INTEGER == pow.getDatatype()) {
            return new SesameNumericValue(a.decimalValue().pow(pow.intValue()));
        } else {
            double r = Math.pow(a.doubleValue(), pow.doubleValue());
            Type precision = maxPrecision(a, pow);
            switch (precision) {
                case INTEGER:
                    return new SesameNumericValue((int) r);
                case LONG:
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, result;

        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = mc.valueOf(a.sign());

        solutions.put(
                stack.push(result));
    }
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;
        double a;
        NumericValue result;

        a = mc.toNumericValue(stack.getFirst()).doubleValue();
        stack = stack.getRest();

// TODO: check for undefined values
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, result;

        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = mc.valueOf((int) Math.ceil(a.doubleValue()));

        solutions.put(
                stack.push(result));
    }
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, result;

        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = mc.valueOf(Math.exp(a.doubleValue()));

        solutions.put(
                stack.push(result));
    }
View Full Code Here

                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {

        RippleList stack = arg;

        NumericValue a, result;

        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = a.abs();

        solutions.put(
                stack.push(result));
    }
View Full Code Here

                      final ModelConnection mc) throws RippleException {

        RippleList stack = arg;

        double a;
        NumericValue result;

        a = mc.toNumericValue(stack.getFirst()).doubleValue();
        stack = stack.getRest();

        // Apply the function only if it is defined for the given argument.
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, b, result;

        b = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();
        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = a.mul(b);

        solutions.put(
                stack.push(result));
    }
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue result;

        result = mc.valueOf(Math.random());

        solutions.put(
                stack.push(result));
View Full Code Here

TOP

Related Classes of net.fortytwo.ripple.model.NumericValue

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.