Skip to Main Content Skip to Search
Product Documentation

Using fimath to Share Arithmetic Rules

There are two ways of sharing fimath properties in Fixed-Point Toolbox software:

Sharing fimath properties across fi objects ensures that the fi objects are using the same arithmetic rules and helps you avoid "mismatched fimath" errors.

Using the Global fimath to Share Arithmetic Rules

You can ensure that your fi objects are all using the same fimath properties by associating them with the global fimath. To associate a fi object with the global fimath, you can:

To learn how to configure the global fimath, see Working with the Global fimath.

Using fimath Objects to Share Arithmetic Rules

You can also use a fimath object to define common arithmetic rules that you would like to use for multiple fi objects. You can then create your fi objects, using the same fimath object for each. To do so, you must also create a numerictype object to define a common data type and scaling. Refer to Working with numerictype Objects for more information on numerictype objects. The following example shows the creation of a numerictype object and fimath object, and then uses those objects to create two fi objects with the same numerictype and fimath attributes:

T = numerictype('WordLength', 32, 'FractionLength', 30)
 
T =
 

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 30

F = fimath('RoundMode', 'floor', 'OverflowMode', 'wrap') 
 
F =
 

             RoundMode: floor
          OverflowMode: wrap
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128

a = fi(pi, T, F)
 
a =
 
   -0.8584


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 30

             RoundMode: floor
          OverflowMode: wrap
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128
 
b = fi(pi/2, T, F)
 
b =
 
    1.5708


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 32
        FractionLength: 30

             RoundMode: floor
          OverflowMode: wrap
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128
  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS