Using fixed-point variables Using fixed-point variables For target systems that do not include floating-point capabilities, Rational Rhapsody in C provides an option to use fixed-point variables. This is done by scaling integer variables so that they can represent non-integral values. Rational Rhapsody uses the 2 factorial approach to achieve this. For example, setting the bit that usually represents 2^0 to represent 2^-3 (.125). For each such variable, the user specifies the word-size and the precision of the variable. The specific steps involved are described in Defining fixed-point variables .
Defining fixed-point variables The elements required for defining fixed-point variables are included in a profile called FixedPoint . This profile contains: Љ Predefined types representing 8, 16, and 32-bit fixed-point variables: FXP_8Bit_T , FXP_16Bit_T , FXP_32Bit_T . (These are the only types that can be used with fixed-point operations.) Љ A “new term” stereotype, applicable to attributes, called FixedPointVar , with a tag called FXP_Shift which is used to define the scale of the fixed-point variable. The word-size is determined by the type chosen, while the shift to use is determined by the value entered for the tag FXP_Shift .
The profile uses a file called FixedPoint.h , which contains: Љ Typedefs representing the predefined fixed-point variable types Љ Macros that are used for carrying out operations on fixed-point variables. The file is “included” into the generated code where fixed-point variables are generated. To define a fixed-point variable: 1. Add the FixedPoint profile to your project as a reference. Note: The FixedPoint profile is added with Rational Rhapsody only if you selected the Automotive add-on during installation. 2. In the browser, right-click the element that will contain the fixed-point variables and select Add New > General Elements > FixedPointVar . 3. Name the new variable.
Rational Rhapsody 117