看板 EE_DSnP 關於我們 聯絡資訊
※ 引述《s2kip (老人老人老人...)》之銘言: : 標題: [問題] modCalc.ref的結果 : 時間: Thu Apr 10 19:03:04 2008 : : : 今天測試自己的程式和老師的程式運作起來有沒有差的時候 : : 結果 modCalc.ref 似乎有點問題說@@ : : 他跑出底下的結果 : : mcalc> mvar a 3 : a = 3 : : mcalc> mvar b 5 : b = 5 : : mcalc> msub c b a : c(0) = 5 - 3 : ^^^^ : : 之後去看c的值也真的是零@@" : : -- : ※ 發信站: 批踢踢實業坊(ptt.cc) : ◆ From: 140.112.247.133 : 推 bnsblue:同樣的問題~ 04/10 19:30 : 推 bnsblue:剛剛po了又刪的那篇是我耍笨了XDDD 04/10 19:38 : 推 ric2k1:Please do "mset xx" first. Otherwise, the default is 04/10 20:29 : → ric2k1:INT_MAX and the sub operation will cause int overfloat. 04/10 20:30 : → s2kip:是耶~ 謝謝老師~ 04/10 21:37 : 推 trancewu:請問為什麼會overfloat?INT_MAX不是和平常的加減一樣嗎? 04/10 23:15 Since we use "int" to record ModNum::_num, the arithmetic operations will not work properly when the _modulus = INT_MAX (7fffffff)... In your example: num 2's compl to-ModNum ----------------------------------- 5 = 5 = 5 -3 = fffffffd = 7ffffffc (<= -3 + INT_MAX; an overfloat occurs) ----------------------------------- 5-3 = ,,,,,,,, = 80000001 => 0 (<= 80000001 + INT_MAX; another overfloat) Anyway, just use mset first... it will make more sense. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.21.241
ric2k1:提醒自己: 明年 _modulus default 要設成小一點的數字... 04/10 23:46