필터 지우기
필터 지우기

atan2(0, -55) is different from atan2(-1*0, -55)

조회 수: 1 (최근 30일)
Kyle
Kyle 2016년 9월 8일
편집: Kyle 2016년 9월 9일
Just found that
>> atan2(0, -55)
ans =
3.1416
>> atan2(-1*0, -55)
ans =
-3.1416
I don't understand how is this possible? -1 *0 doesn't equal to 0?? How can I convert such behaviour to C++?

채택된 답변

Steven Lord
Steven Lord 2016년 9월 9일
Numerically they are equal.
z = 0;
mz = -0;
z == mz
However, they are not identical.
format hex
z
mz
Note that the sign bits are different. You can see this:
format
plusInf = 1/z
minusInf = 1/mz
As for how you can translate this to C++ ... why not just call std::atan2?
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
...
If y is ±0 and x is negative or -0, ±π is returned
This is specifically called out in section 9.2.1 of IEEE 754-2008.
  댓글 수: 1
Kyle
Kyle 2016년 9월 9일
편집: Kyle 2016년 9월 9일
Your answer explains well, thank you. std::atan2(-1*0, -55) will be the same as std::atan2(1*0, -55), although I tried all kinds of data type in the two inputs. My current solutions is std::atan2(-1*(0 + 0.000000001), -55).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by