Classes and types 4. Open the Features window for the new variable, and for Type select one of the fixed-point variable types ( FXP_8Bit_T , FXP_16Bit_T , or FXP_32Bit_T ). (If you do not see these types in the list, click Select and locate the relevant type in the tree that is displayed.) 5. Set the shift to use by providing a value for the tag FXP_Shift (default value is 4). (The variable that was created already has the Fixed-Point stereotype applied to it.) Operations permitted for fixed-point variables The following operations can be performed on fixed-point variables: Љ Arithmetic:
addition, subtraction, multiplication, division Љ Assignment (=) Љ Relational operators ( , =, = =, !=) To carry out the operations, you use the relevant macros that are contained in FixedPoint.h . For example to add fixed-point variables, use the macro FXP_ASSIGN_SUM . (Note that some of the macros in this file are macros that are called by the operation macros. These macros should not be called directly.) Restrictions on use of fixed-point variables Keep the following points in mind when working with fixed-point variables: Љ The supported operations can only be performed on fixed-point variables, and not on the result of fixed-point calculations. For example, these are not permitted:
FXP_ASSIGN_SUM(FXP_ASSIGN_SUM(varA,varB),varC). Љ Operations can be performed on fixed-point variables only. If you try to use one of the operations with a combination of fixed-point and ordinary variables, compilation errors will result. Љ The shift specified can range from 0 to (word size - 1). Rational Rhapsody does not check that the shift you entered for the variable is within this range. Љ When calling a function that takes a fixed-point variable as an argument, make sure that the variable provided to the function has the same fixed-point characteristics (word size and shift) as the defined argument.
Љ When calling a function that returns a fixed-point variable, make sure that the return value is being assigned to a variable that has the same fixed-point characteristics (word size and shift) as the defined return type. Љ Programmers must take into account that operations on fixed-point variables can result in an arithmetic overflow. Љ Programmers must take into account that operations on fixed-point variables can result in a loss of precision. 118 User Guide