[問題] sqrt回傳值錯誤

看板C_and_CPP作者 (NEWLYMOON)時間7年前 (2018/05/24 11:40), 編輯推噓1(101)
留言2則, 2人參與, 7年前最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) win7 64bit 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC2005 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 使用math.h的sqrt(),但回傳值錯誤,ex:sqrt(25.0)=1057620607 不過如果把sqrt()再包過一層,其回傳值就會正確,ex:fsqrt(25.0)=5 餵入的資料(Input): 25 預期的正確結果(Expected Output): 5 錯誤結果(Wrong Output): 1057620607 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) double fsqrt(double x) { return sqrt(x); } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.96.32.110 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1527133241.A.7E2.html

05/24 14:44, 7年前 , 1F
只貼"正確"的 fsqrt 我們根本不知道你"錯誤"的 sqrt 怎麼錯
05/24 14:44, 1F

05/24 14:48, 7年前 , 2F
compiler選錯程式
05/24 14:48, 2F
文章代碼(AID): #1R1ZGvVY (C_and_CPP)