03.08.2013 Views

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

PTOLEMY II - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Expressions<br />

value. For example,<br />

fix(5.375, 8, 3)<br />

will yield 3.968758, the maximum value possible with the (8/3) precision.<br />

In addition to the fix() function, the expression language offers a quantize() function. The arguments<br />

are the same as those of the fix() function, but the return type is a DoubleToken or DoubleMatrixToken<br />

instead of a FixToken or FixMatrixToken. This function can therefore be used to quantize<br />

double-precision values without ever explicitly working with the fixed-point representation.<br />

To make the FixToken accessible within the expression language, the following functions are<br />

available:<br />

To create a single FixPoint Token using the expression language:<br />

fix(5.34, 10, 4)<br />

This will create a FixToken. In this case, we try to fit the number 5.34 into a 10 bit representation<br />

with 4 bits used in the integer part. This may lead to quantization errors. By default the round<br />

quantizer is used.<br />

To create a Matrix with FixPoint values using the expression language:<br />

fix([ -.040609, -.001628, .17853 ], 10, 2)<br />

This will create a FixMatrixToken with 1 row and 3 columns, in which each element is a FixPoint<br />

value with precision(10/2). The resulting FixMatrixToken will try to fit each element of the given<br />

double matrix into a 10 bit representation with 2 bits used for the integer part. By default the round<br />

quantizer is used.<br />

To create a single DoubleToken, which is the quantized version of the double value given, using<br />

the expression language:<br />

quantize(5.34, 10, 4)<br />

This will create a DoubleToken. The resulting DoubleToken contains the double value obtained by<br />

fitting the number 5.34 into a 10 bit representation with 4 bits used in the integer part. This may<br />

lead to quantization errors. By default the round quantizer is used.<br />

To create a Matrix with doubles quantized to a particular precision using the expression language:<br />

quantize([ -.040609, -.001628, .17853 ], 10, 2)<br />

This will create a DoubleMatrixToken with 1 row and 3 columns. The elements of the token are<br />

obtained by fitting the given matrix elements into a 10 bit representation with 2 bits used for the<br />

integer part. Instead of being a fixed point value, the values are converted back to their double representation<br />

and by default the round quantizer is used.<br />

3.9 Units<br />

Ptolemy <strong>II</strong> supports units systems, which are built on top of the expression language. Units systems<br />

allow parameter values to be expressed with units, such as “1.0 * cm”, which is equal to “0.01 *<br />

meters”. These are expressed this way (with the * for multiplication) because “cm” and “meters” are<br />

actually variables that become in scope when a units system icon is dragged in to a model. A few simple<br />

units systems are provided (mainly as examples) in the utilities library.<br />

Heterogeneous Concurrent Modeling and Design 115

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!