How can I create a script that can perform division on both floating point numbers and fixed point numbers?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 6 de Nov. de 2025
Respondida: MathWorks Support Team
el 6 de Nov. de 2025
I want to create a script that can perform division on both double-precision floating point numbers and fixed point number. However, I noticed that fixed point numbers require a different function to perform division in the divide documentation.
How can I create a script that handles both types of numbers?
Respuesta aceptada
MathWorks Support Team
el 6 de Nov. de 2025
You can extract the numeric type of the numerator:
function out = myDivide(u0, u1)
T0 = 273.15;
u0_k = u0 + T0;
u1_k = u1 + T0;
ntDiv = fixed.extractNumericType(u0);
out = divide(ntDiv,u0_k,u1_k);
end
This uses the fixed.extractNumericType function, which works for double and fixed-point types. The output type will have the same scaling as the numerator.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Fixed-Point Designer en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!