Re: [問題] 請問0.0 和-0.0
總結一下 大家給的意見和小弟我試出來的結果
一句話來說就是 "VS2003 在輸出的部分 不合IEEE754規範"
借用james732的程式碼 http://ideone.com/vlWHPc 來看看變數的binary
跑出來的結果
VS2003:
10000000000000000000000000000000
a == 0.00 == 0
VS2008:
10000000000000000000000000000000
a == -0.00 == 0
看起來變數沒有問題 將值給入變數時 負號都有加上去
出問題的是在 "printf出來的時候"
這和azureblaze兄提供的連結內容http://ppt.cc/AHEu 一致
節錄部分:
The VS 2003 version of printf outputs “0〃 for both -0 and +0, while the VS
2008 version of printf has been changed to output “-0〃 for -0. The reason
is that VS 2003 was not compliant with the standard, so it was changed
(starting with VS 2005) so that it’s now compliant.
感謝各位版友不吝提供意見 讓小弟在浮點數部分重新好好地複習了一下
改正不少觀念 謝謝大家m(o)m
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.112.106
推
11/09 17:28, , 1F
11/09 17:28, 1F
推
11/09 19:29, , 2F
11/09 19:29, 2F
※ 編輯: jokingfish 來自: 122.117.112.106 (11/12 09:39)
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):
問題
1
18