Skip to Main Content Skip to Search
Product Documentation

Working with the Global fimath

The global fimath is the set of fimath properties that fi objects associate with, and fimath constructors return, when you do not specify any fimath properties in the constructor. If you do not specify any fimath properties in a fi object constructor, the resulting fi object associates itself with the global fimath. If you specify one or more fimath object properties in a fi object constructor, the resulting fi object has a local fimath object. All fimath object properties that you do not specify in a fi or fimath object constructor inherit their values from the global fimath. The factory-default setting of the global fimath has the following properties:

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128

If you create a fi object with a local fimath object, you can use dot notation to change the local fimath object properties. You can also use dot notation to remove a local fimath object from an existing fi object, and associate that fi object with the global fimath. For example, if the fi object a has a local fimath object, you can use the syntax a.fimath = [] to remove its local fimath object. When you do so, a becomes associated with the global fimath.

You can configure your global fimath settings using the Fixed-Point Toolbox globalfimath, saveglobalfimathpref, removeglobalfimathpref, and resetglobalfimath functions. The global fimath allows you to define your own set of fimath properties for all fi and fimath objects to use as a default. See the following sections for more information about the Fixed-Point Toolbox global fimath functions:

For information on how fi objects with local fimath objects interact with fi objects associated with the global fimath, see the following section:

fimath Rules for Fixed-Point Arithmetic

Configuring the Global fimath

You can configure the global fimath using the globalfimath function. When you provide an output argument, this function returns a handle object to the global fimath. You can then control the global fimath properties through that handle object. The following syntaxes provide you with a handle object to the global fimath:

The global fimath properties you set with the globalfimath function apply only in your current MATLAB session. To save the global fimath for use in future MATLAB sessions, use the saveglobalfimathpref function.

Saving the Global fimath

If you want to use the current global fimath in future MATLAB sessions, you must save it as a preference. The saveglobalfimathpref function saves the current global fimath as a preference, and MATLAB uses that global fimath in all future sessions.

To use the current global fimath in all future MATLAB sessions, type

saveglobalfimathpref;

at the MATLAB command line. MATLAB now uses the current global fimath in all of your future MATLAB sessions.

Resetting the Global fimath to the Factory Default

There are two ways to reset the global fimath to the factory default in your current MATLAB session:

Unless you choose to configure the global fimath again, MATLAB uses the factory-default setting of the global fimath for the remainder of your MATLAB session. For example, after resetting the global fimath to the factory default, MATLAB returns the following fi and fimath objects:

b = fi(pi)

b =
    3.1416

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 13

b.fimath

ans =

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128

F1 = fimath

F1 =

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128

To reset the global fimath to the factory default for all future MATLAB sessions, remove your global fimath from the MATLAB preferences. To do so, type

removeglobalfimathpref;

at the MATLAB command line. This command sets the global fimath back to its factory-default configuration for all future MATLAB sessions.

Using the Global fimath with the MATLAB Function Block

For information about using the global fimath with the MATLAB Function block, see the following section:

Using fimath Objects in MATLAB Function Blocks
  


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