Configure global fimath and return handle object
G = globalfimath
G = globalfimath('PropertyName1',PropertyValue1,...)
G = globalfimath(f)
G = globalfimath returns a handle object to the global fimath. The global fimath has identical properties to a fimath object but applies globally.
G = globalfimath('PropertyName1',PropertyValue1,...) sets the global fimath using the named properties and their corresponding values. Properties that you do not specify in this syntax are automatically set to that of the current global fimath.
G = globalfimath(f) sets the properties of the global fimath to match those of the input fimath object f, and returns a handle object to it.
Unless, in a previous release, you used the saveglobalfimathpref function to save global fimath settings to your MATLAB® preferences, the global fimath properties you set with the globalfimath function apply only to your current MATLAB session. It is best practice to remove global fimath from the MATLAB preferences so that you start each MATLAB session using the default fimath settings. To remove the global fimath, use the removeglobalfimathpref function.
Use the globalfimath function to set, change, and reset the global fimath.
Create a fimath object and use it as the global fimath.
G = globalfimath('RoundMode','Floor','OverflowMode','Wrap')
G = RoundingMethod: Floor OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision
Create another fimath object using the new default.
F1 = fimath
F1 = RoundingMethod: Floor OverflowAction: Wrap ProductMode: FullPrecision SumMode: FullPrecision
Create a fi object, A, associated with the global fimath.
A = fi(pi)
A = 3.1416 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 13
Now set the "SumMode" property of the global fimath to "KeepMSB" and retain all the other property values of the current global fimath.
G = globalfimath('SumMode','KeepMSB')
G = RoundingMethod: Floor OverflowAction: Wrap ProductMode: FullPrecision SumMode: KeepMSB SumWordLength: 32 CastBeforeSum: true
Change the global fimath by directly interacting with the handle object G.
G.ProductMode = 'SpecifyPrecision'
G = RoundingMethod: Floor OverflowAction: Wrap ProductMode: SpecifyPrecision ProductWordLength: 32 ProductFractionLength: 30 SumMode: KeepMSB SumWordLength: 32 CastBeforeSum: true
Reset the global fimath to the factory default by calling the reset method on G. This is equivalent to using the resetglobalfimath function.
G = RoundingMethod: Nearest OverflowAction: Saturate ProductMode: FullPrecision SumMode: FullPrecision
If you always use the same fimath settings and you are not sharing code with other people, using the globalfimath function is a quick, convenient method to configure these settings. However, if you share the code with other people or if you use the fiaccel function to accelerate the algorithm or you generate C code for your algorithm, consider the following alternatives.
|Goal||Issue Using globalfimath||Solution|
If you share code with someone who is using different global fimath settings, they might see different results.
Separate the fimath properties from your algorithm by using types tables. For more information, see Separate Data Type Definitions from Algorithm.
Accelerate your algorithm using fiaccel or generate C code from your MATLAB algorithm using codegen
You cannot use globalfimath within that algorithm. If you generate code with one globalfimath setting and run it with a different globalfimath setting, results might vary. For more information, see Specifying Default fimath Values for MEX Functions.
Use types tables in the algorithm from which you want to generate code. This insulates you from the global settings and makes the code portable. For more information, see Separate Data Type Definitions from Algorithm.