[問題] float 小數位數

看板C_and_CPP作者 (j1215tnfsh)時間12年前 (2011/11/15 01:39), 編輯推噓0(006)
留言6則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) C:B 10.05 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) N/A 問題(Question): float 跟 double 所存的小數點的位數最多只能到16位? 餵入的資料(Input): 1.12345678901234567890123 預期的正確結果(Expected Output): 1.12345678901234567890123 錯誤結果(Wrong Output): 1.12345678901234570000000 程式碼(Code):(請善用置底文網頁, 記得排版) float f; scanf("%f", &f); printf("%.23f", f); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.255.181.60

11/15 01:41, , 1F
double的精確度就是只到15~16位左右~
11/15 01:41, 1F

11/15 01:41, , 2F
我想知道為什麼~
11/15 01:41, 2F

11/15 01:42, , 3F
去查一下IEEE 754
11/15 01:42, 3F

11/15 02:13, , 4F
Single Precision , Mantissa(23bits), log(2^(23+1))
11/15 02:13, 4F

11/15 02:14, , 5F
=24 * log2=7.22 ; double--> 53 * log2 = 15.95
11/15 02:14, 5F
文章代碼(AID): #1EmL8sXv (C_and_CPP)