필터 지우기
필터 지우기

Divide by Zero

조회 수: 103 (최근 30일)
D G
D G 2012년 6월 26일
I am wondering, why does MATLAB give infinity for the calculation 1 / 0?
Shouldn't this throw an error, return NaN, or be a complex infinity?
Just looking for some reasoning for this invalid calculation.
Thanks!
  댓글 수: 1
D G
D G 2012년 6월 26일
I would also like to know if it is possible to have MATLAB throw an error on divide by zero.

댓글을 달려면 로그인하십시오.

채택된 답변

Thomas
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
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.
Sharon
Sharon 2012년 6월 27일
+1 for the concise answer..

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2012년 6월 26일
For stopping on division by zero see:
warning on MATLAB:divideByZero
dbstop if warning MATLAB:divideByZero
and
dbstop if naninf

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by