Did the default rounding behaviour of num2str change between R2016b and R2018b?
Mostrar comentarios más antiguos
I have some code that produces a different result when run in R2018b than it did in R2016b, and I've identified that num2str (which is used to create a text file to exchange data with an external tool) is giving different output for some values. For example, in R2016b:
>> num2str(1.51535)
ans =
1.5154
but in R2018b:
>> num2str(1.51535)
ans =
'1.5153'
I can work around this difference, but I can't find anything about this change in the MATLAB release notes, so before I commit any code changes I want to be sure that this is actually a change in MATLAB's default behaviour and not some setting I've overlooked that might be different between my R2016b and R2018b installations. Is this the case?
2 comentarios
Tom Hawkins
el 9 de Nov. de 2018
I think the R2018 result is correct. Floating point binary is simply rounded to the nearest decimal value, because what you have is not a tie of the binary value relative to the rounded decimal value (for a tie the value could be something like 1+pow2(-53), or similar). In any case, I think that that value should be rounded down:
>> fprintf('%.30f\n',1.51535)
1.515349999999999974775732880516
Try using James Tursa's excellent FEX submission:
Of course this does not answer your question, "what changed?".
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!