matlab negative and positive infinity problem

hi there,
I am quite confused about how matlab deals with inf and -inf. Here is the problem I confronted
x0p = 0;
b = 0.0050;
y0p =0;
(x0p-b)/y0p
ans =
Inf
But it should be -inf. I changed the value of b but still got the same answer. I tried using numbers directly and it seems correct as shown below. I don't know the mechanism behind it. So I hope someone could help me figure it out.
-1/0
ans =
-Inf
Cheers,
Jianan

3 件のコメント

madhan ravi
madhan ravi 2019 年 5 月 4 日
編集済み: madhan ravi 2019 年 5 月 4 日
sprintf('%.32f',x0p) % what does it result to?
I get -Inf btw.
Walter Roberson
Walter Roberson 2019 年 5 月 4 日
-Inf is what shows up for me in R2019a. Which version are you using, on which operating system?
I suggest you use num2hex(x0p) and y0p to verify that they are true zeros. Also, store the result in a variable and use num2hex() on it. -inf is fff followed by all 0, and +inf is 7ff followed by all 0.
Jianan He
Jianan He 2019 年 5 月 4 日
Thanks guys, I found my problem. I didn't realize that zero can be negative or positive in matlab.
sprintf('%.32f',y0p)
ans =
'-0.00000000000000000000000000000000'
Thanks again, it's my first time asking questions in community and I appreciate your guys help!

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2019 年 5 月 4 日

コメント済み:

2019 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by