MATLAB: Do I receive the warning “Parameter precision loss occurred for ‘InitialValue'” when I set the ‘DataType’ parameter of a signal to ‘single’ and I specify a non-zero ‘Initial value’ parameter of the signal

simulink

When I specify the 'DataType' property of a signal as 'single', I must enter a variable of type 'double' as the 'Initial value' parameter for this signal. This causes Simulink to convert the variable specified for the 'Initial value' from type 'double' to type 'single'. To reproduce this issue, follow these steps:
1 – Create a Simulink model with a Data Store Read block
2 – Open the Model Explorer and create a new signal
3 – Set the 'DataType' property of the signal to 'single'
4 – Set the 'Initial value' parameter to any non-integer value, for example you can use the value 73.3.
4 – Execute the model and notice the warning displayed in the MATLAB command window.

Best Answer

This enhancement has been incorporated in Simulink 7.2 (R2008b). For previous product releases, to work around this limitation, two solutions are available:
One solution is to set the 'Detect precision loss' diagnostic option to 'none'.
Another solution is to use a variable which will not lose its precision when converted from 'double' to 'single'. In the previous example, the value 73.3 loses precision. When it is converted to type 'single', it becomes 73.3000031. This result can be converted to type 'double' to be used as 'Initial value' parameter of the signal.
In the following line of MATLAB code, the example value of 73.3 is converted to type 'single'. The result (73.3000031) is then converted to 'double' to be used as 'Initial value' parameter of a signal:
double(single(73.3))