Products & Services Solutions Academia Support User Community Company

Learn more about Fixed-Point Toolbox   

Working with the Global fimath

The global fimath is the set of fimath properties that fi constructors 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. You can partially specify a fimath object in a fi or fimath constructor using property name/property value pairs. Doing so allows the remaining unspecified fimath properties to 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
         CastBeforeSum: true

You can use dot notation to change any fimath property of a fi object after creating the fi object. You can also use dot notation to associate an existing fi object with the global fimath. For example, the syntax a.fimath = [] removes the attached fimath object from a and associates a with the global fimath.

You can configure the global fimath using the Fixed-Point Toolbox setdefaultfimath, savedefaultfimathpref, removedefaultfimathpref, and resetdefaultfimath 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. The following sections show you how to:

See the following section for information on how a fi object with an attached fimath object interacts with a fi object associated with the global fimath:

fimath Rules for Fixed-Point Arithmetic

Configuring the Global fimath

You can configure the global fimath in two ways:

From this point forward (in your current MATLAB session), fi and fimath objects use the global fimath you configured. All fi objects you create without specifying any fimath properties in the constructor associate themselves with the global fimath. You can determine if a fi object is associated with the global fimath by using the isfimathlocal function:

a = fi(pi)
 
a =
    3.1416

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

isfimathlocal(a)

ans =
     0

F1 = fimath

F1 =
 

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

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 savedefaultfimathpref 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

savedefaultfimathpref;

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

You can reset the global fimath to the factory setting at any time by using the resetdefaultfimath function. To do so, type

resetdefaultfimath;

at the MATLAB command line.

When you reset the global fimath, all fi objects that are associated with it become associated with the factory-default fimath properties. 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.

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
         CastBeforeSum: true

F1 = fimath

F1 =

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

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

removedefaultfimathpref;

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 Embedded MATLAB Function Block

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

Using fimath Objects in Embedded 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-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS