Home   :   Matrix Language   :   Primitive Action Statements   :   Cast Evaluation Statements

Casting Evaluation Statements

 

Statements

 

AdditionCast

SubtractionCast

MultiplicationCast

DivisionCast

DividendCast

DivisorCast

AdditionDataCast

SubtractionDataCast

MultiplicationDataCast

 

 

General

 

Cast evaluation statements function in exactly the same way as regular evaluation statements except that they provide a means to define the type of the result of an intermediate calculation so that the resultant value can be assigned to a data item of a compatible type.

 

 

AdditionCast Statement

 

This statement works in exactly the same way as the Addition Statement except that the intermediate result can be given a type which is the same as the type of the receiving data item.

 

Assignment

Evaluation:integer_data

AdditionCast:Type_Integer

AdditionData

<<IntegerOne>>

Fixed_data

Entity.Integer_attribute

 

ANSI C Code Generation:

 

| +(adm_int_type_integer_typ)(... + ... + ...)

|

\Addition         +(adm_int_type_integer_typ)(

...             +...

|               +

...             +...

|               +

...             +...

/Addition         )

 

 

SubtractionCast Statement

 

Assignment

Evaluation:integer_data

SubtractionCast:Type_Float

AdditionData

<<IntegerOne>>

Integer_data

Entity.Integer_attribute

 

 

MultiplicationCast Statement

 

Assignment

Evaluation:integer_data

MultiplicationCast:Type_Float

AdditionData

<<IntegerOne>>

Integer_data

Entity.Integer_attribute

 

 

DivisionCast Statement

 

Assignment

Evaluation:aaaa

DivisionCast:Type_Float

Dividend

Addition

AdditionData

bbbb

Divisor

Addition

AdditionData

cccc

 

 

DividendCast Statement

 

Assignment

Evaluation:aaaa

Division

DividendCast:Type_Float

Addition

AdditionData

bbbb

Divisor

Addition

AdditionData

cccc

 

 

DivisorCast Statement

 

Assignment

Evaluation:aaaa

Division

Dividend

Addition

AdditionData

bbbb

DivisorCast:Type_Integer

Addition

AdditionData

cccc

 

 

AdditionDataCast Statement

 

Assignment

Evaluation:integer_data

Addition

AdditionDataCast:Type_Float

<<IntegerOne>>

-Integer_data

Entity.Integer_attribute

 

 

SubtractionDataCast Statement

 

Assignment

Evaluation:integer_data

Addition

SubtractionDataCast:Type_Float

<<IntegerOne>>

-Integer_data

Entity.Integer_attribute

 

 

MultiplicationDataCast Statement

 

Assignment

Evaluation:integer_data

Addition

MultiplicationDataCast:Type_Float

<<IntegerOne>>

-Integer_data

Entity.Integer_attribute

 

 

Type Casting Example

 

This example shows how casting modifies the generated code in an ANSI C Model Compiler.

 

Matrix model code:

 

Assignment

Evaluation:amount

DivisionCast:Type_Fixed

DividendCast:Type_Integer

DivisionCast:Type_Fixed

DividendCast:Type_Float

AdditionCast:Type_Integer

AdditionDataCast:Type_Integer

amount

<<IntegerOne>>

DivisorCast:Type_Integer

AdditionCast:Type_Fixed

AdditionDataCast:Type_Float

amount

<<IntegerOne>>

AdditionCast:Type_Float

AdditionDataCast:Type_Integer

Type_Integer'amount

<<IntegerOne>>

DivisorCast:Type_Float

AdditionCast:Type_Integer

AdditionDataCast:Type_Fixed

amount

<<IntegerOne>>

 

Generated ANSI C code:

 

    pdt_amount =

        +(adm_fxd_type_fixed_typ)(

            +(adm_int_type_integer_typ)(

                +(adm_fxd_type_fixed_typ)(

                    +(adm_flt_type_float_typ)(

                        +(adm_int_type_integer_typ)(

                            +(adm_int_type_integer_typ)(

                                +pdt_amount

                                +

                                1

                            )

                        )

                    )

                    /

                    +(adm_int_type_integer_typ)(

                        +(adm_fxd_type_fixed_typ)(

                            +(adm_flt_type_float_typ)(

                                +pdt_amount

                                +

                                1

                            )

                            +

                            +(adm_flt_type_float_typ)(

                                +(adm_int_type_integer_typ)(

                                    +(adm_int_type_integer_typ)pdt_amount

                                    +

                                    1

                                )

                            )

                        )

                    )

                )

            )

            /

            +(adm_flt_type_float_typ)(

                +(adm_int_type_integer_typ)(

                    +(adm_fxd_type_fixed_typ)(

                        +pdt_amount

                        +

                        1

                    )

                )

            )

        );

Copyright 2017 Dark Matter Systems Ltd. All Rights Reserved.