Main Content

Simulate and Generate HDL Code for the Float Typecast Block

This example shows how you can use the Float Typecast block to extract the sign, exponent, and mantissa bits from a floating-point input, and then convert the bits back to a floating-point output after performing any computations.

Open the hdlcoder_float_typecast_example model.


The model multiplies the floating-point input by two to produce the floating-point output. To multiply the input, the algorithm increments the exponent by one. Open the HDL_DUT subsystem.


The model is already configured for HDL compatibility by using the hdlsetup function. Simulate the model.


Before you generate HDL code, enable the Native Floating Point mode.

nfpconfig = hdlcoder.createFloatingPointTargetConfig('NATIVEFLOATINGPOINT');
hdlset_param('hdlcoder_float_typecast_example', ...
                            'FloatingPointTargetConfiguration', nfpconfig);

Generate HDL code for the HDL_DUT subsystem.