Divide by Zero
146 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Thomas
2012-6-26
Actually Inf returns the IEEE arithmetic representation for positive infinity.
Infinity results from operations like division by zero and overflow, which lead to results too large to represent as conventional floating-point values. An attempt to divide a floating point number by zero will lead to +-infinity by the IEEE 754 floating point standard
while NaN returns the IEEE arithmetic representation for Not-a-Number (NaN). These result from operations which have undefined numerical results. The IEEE floating-point standard, supported by almost all modern floating-point units, specifies that every floating point arithmetic operation, including division by zero, has a well-defined result.
7 个评论
James Tursa
2012-6-26
MATLAB certainly does it the way I want, which is to generate a real result for real inputs, and to let the h/w do the native IEEE calculation without inserting a lot of performance killing checks like Walter mentioned. I certainly would not want those checks to be the default if it significantly slowed performance. You can always manually check your results for NaN or Inf, and if you need it to stop then maybe do what Jan suggests.
更多回答(1 个)
Jan
2012-6-26
For stopping on division by zero see:
warning on MATLAB:divideByZero
dbstop if warning MATLAB:divideByZero
and
dbstop if naninf
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!