[問題] 基本程式設計概念的問題

看板PLT (程式語言與理論)作者 (哲)時間17年前 (2008/01/21 01:39), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串1/1
(1) Rewrite the following pseudo-code if statement expression in a more realistic manner assuming that variables a and b are of type real: if (a = b) then .... (2) Explain why this is necessary. 這題好像是關於兩個實數不太可能相等的問題,但不知道該怎麼作答。 這是澳洲某大學 2006 年期末考題,請各位高手幫忙。 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.112.16.250 ※ 編輯: trickli 來自: 59.112.16.250 (01/21 01:58)

02/02 21:07, , 1F
浮點數,千萬不要直接拿來做 相等的判斷。
02/02 21:07, 1F

02/02 21:07, , 2F
if (相對誤差of(a,b) < 1e-6) then // 視為興等
02/02 21:07, 2F
文章代碼(AID): #17auT7U4 (PLT)
文章代碼(AID): #17auT7U4 (PLT)