Package ptolemy.data

Examples of ptolemy.data.FixToken


            Local tokenLocal = _buildConstantTokenLocal(body, insertPoint,
                    localName, stringTokenClass, stringTokenConstructor,
                    StringConstant.v(((StringToken) token).stringValue()));
            return tokenLocal;
        } else if (token instanceof FixToken) {
            FixToken fixToken = (FixToken) token;
            FixPoint fixValue = fixToken.fixValue();
            List args = new ArrayList(3);

            // Some possible loss of precision?
            args.add(DoubleConstant.v(fixValue.doubleValue()));
            args.add(IntConstant.v(fixValue.getPrecision().getNumberOfBits()));
View Full Code Here


                            .notSupportedConversionMessage(token, toString()));
                }
                // Try to create a new [fix] type with just one member.
                // The following conversion will fail if the member cannot
                // be converted to an int.
                FixToken singleMember = FixToken.convert(token);
                FixPoint[][] matrix = new FixPoint[1][1];
                matrix[0][0] = singleMember.fixValue();
                return new FixMatrixToken(matrix);
            }
        }
View Full Code Here

            if (!address.hasToken(0)) {
                return;
            }

            FixToken addressToken = (FixToken) address.get(0);
            FixPoint addressFixValue = addressToken.fixValue();

            _checkFixTokenWidth(addressToken, _addressWidth);

            addressValue = addressFixValue.getUnscaledValue().intValue();

            if (addressValue >= _capacity) {
                throw new IllegalActionException(this,
                        "Address is out of range.");
            }

            ArrayToken valuesArray = (ArrayToken) values.getToken();
            FixPoint value = new FixPoint(((ScalarToken) valuesArray
                    .getElement(addressValue)).intValue());
            Token result = new FixToken(value);
            if (result == null) {
                result = Token.NIL;
            }

            sendOutput(output, 0, result);
View Full Code Here

     *  If there is no inputs, then produce null.
     *  @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        FixToken result = null;
        Precision precision = new Precision(0, 1, 0);

        if (A.isKnown() && B.isKnown()) {
            result = new FixToken(0, precision);
            FixToken inputA = new FixToken();
            FixToken inputB = new FixToken();

            if (A.hasToken(0)) {
                inputA = (FixToken) A.get(0);
            }

            if (B.hasToken(0)) {
                inputB = (FixToken) B.get(0);
            }

            if (inputA.fixValue().getPrecision().getNumberOfBits() != inputB
                    .fixValue().getPrecision().getNumberOfBits()) {

                throw new IllegalActionException(this,
                        "Input A has different width than Input B port");
            }

            if (operation.getExpression().equals("=")) {
                if (inputA.equals(inputB)) {
                    result = new FixToken(1, precision);
                }
            } else if (operation.getExpression().equals("!=")) {
                if (!inputA.equals(inputB)) {
                    result = new FixToken(1, precision);
                }
            } else if (operation.getExpression().equals("<")) {
                if (inputA.isLessThan(inputB).booleanValue()) {
                    result = new FixToken(1, precision);
                }
            } else if (operation.getExpression().equals("<=")) {
                if (inputA.equals(inputB)
                        || inputA.isLessThan(inputB).booleanValue()) {
                    result = new FixToken(1, precision);
                }
            } else if (operation.getExpression().equals(">")) {
                if (inputA.isGreaterThan(inputB).booleanValue()) {
                    result = new FixToken(1, precision);
                }
            } else if (operation.getExpression().equals(">=")) {
                if (inputA.equals(inputB)
                        || inputA.isGreaterThan(inputB).booleanValue()) {
                    result = new FixToken(1, precision);
                }
            }

            sendOutput(output, 0, result);
        }
View Full Code Here

        } else if (object instanceof Float) {
            returnValue = new FloatToken(((Float) object).floatValue());
        } else if (object instanceof Complex) {
            returnValue = new ComplexToken((Complex) object);
        } else if (object instanceof FixPoint) {
            returnValue = new FixToken((FixPoint) object);
        } else if (object instanceof String) {
            returnValue = new StringToken((String) object);
        } else if (object instanceof boolean[][]) {
            returnValue = new BooleanMatrixToken((boolean[][]) object);
        } else if (object instanceof int[][]) {
            returnValue = new IntMatrixToken((int[][]) object);
        } else if (object instanceof long[][]) {
            returnValue = new LongMatrixToken((long[][]) object);
        } else if (object instanceof double[][]) {
            returnValue = new DoubleMatrixToken((double[][]) object);
        } else if (object instanceof Complex[][]) {
            returnValue = new ComplexMatrixToken((Complex[][]) object);
        } else if (object instanceof FixPoint[][]) {
            returnValue = new FixMatrixToken((FixPoint[][]) object);
        } else if (object instanceof double[]) {
            DoubleToken[] temp = new DoubleToken[((double[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new DoubleToken(((double[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof Complex[]) {
            ComplexToken[] temp = new ComplexToken[((Complex[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new ComplexToken(((Complex[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof int[]) {
            IntToken[] temp = new IntToken[((int[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new IntToken(((int[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof long[]) {
            LongToken[] temp = new LongToken[((long[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new LongToken(((long[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof boolean[]) {
            BooleanToken[] temp = new BooleanToken[((boolean[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new BooleanToken(((boolean[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof String[]) {
            StringToken[] temp = new StringToken[((String[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new StringToken(((String[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else if (object instanceof FixPoint[]) {
            // Create back an ArrayToken containing FixTokens
            FixToken[] temp = new FixToken[((FixPoint[]) object).length];

            for (int j = 0; j < temp.length; j++) {
                temp[j] = new FixToken(((FixPoint[]) object)[j]);
            }

            returnValue = new ArrayToken(temp);
        } else {
            // Package into an ObjectToken.
View Full Code Here

        StringBuffer bits = new StringBuffer();

        // Concat bits from each input port.
        for (int i = 0; i < input.getWidth(); i++) {
            if (input.hasToken(i)) {
                FixToken in = (FixToken) input.get(i);
                bits.append(in.fixValue().toBitString());
            }
        }

        //FIXME: what do we do if input is negative?
        //bits = bits.replace('-', '1');

        FixPoint result = new FixPoint(new BigDecimal(new BigInteger(bits
                .toString(), 2)), new FixPointQuantization(precision, overflow,
                rounding));

        sendOutput(output, 0, new FixToken(result));
    }
View Full Code Here

                                .getExpression().toLowerCase());

                FixPoint result = new FixPoint(((ScalarToken) valuesArray
                        .getElement(_currentIndex)).doubleValue(),
                        new FixPointQuantization(precision, overflow, rounding));
                sendOutput(output, 0, new FixToken(result));
                _outputProduced = true;
            }
        }
    }
View Full Code Here

    public void fire() throws IllegalActionException {
        super.fire();
        Token result = null;

        if (A.isKnown() && B.isKnown()) {
            Token tokenA = new FixToken();
            Token tokenB = new FixToken();

            if (A.hasToken(0)) {
                tokenA = A.get(0);
            }
View Full Code Here

     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (select.isKnown() && A.isKnown() && B.isKnown()) {
            if (select.hasToken(0)) {
                FixToken channel = (FixToken) select.get(0);

                _checkFixTokenWidth(channel, 1);

                _channel = channel.fixValue().getUnscaledValue().intValue();
            }

            Precision outputPrecision = new Precision(
                    ((Parameter) getAttribute("outputPrecision"))
                            .getExpression());

            FixToken tokenA = null;
            FixToken tokenB = null;

            if (A.hasToken(0)) {
                tokenA = (FixToken) A.get(0);
                if (tokenA.fixValue().getPrecision().getNumberOfBits() != outputPrecision
                        .getNumberOfBits()) {

                    throw new IllegalActionException(this,
                            "Input A has different width than the output port");
                }
            }
            if (B.hasToken(0)) {
                tokenB = (FixToken) B.get(0);
                if (tokenB.fixValue().getPrecision().getNumberOfBits() != outputPrecision
                        .getNumberOfBits()) {

                    throw new IllegalActionException(this,
                            "Input B has different width than the output port");
                }
View Full Code Here

                Rounding rounding = Rounding
                        .getName(((Parameter) getAttribute("outputRounding"))
                                .getExpression().toLowerCase());
                FixPoint result = new FixPoint(intResult.doubleValue(),
                        new FixPointQuantization(precision, overflow, rounding));
                sendOutput(output, 0, new FixToken(result));
            }
        } else {
            output.resend(0);
        }
    }
View Full Code Here

TOP

Related Classes of ptolemy.data.FixToken

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.