作者ric2k1 (Ric)
看板EE_DSnP
标题Re: [问题] modCalc.ref的结果
时间Thu Apr 10 23:46:08 2008
※ 引述《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
1F:→ ric2k1:提醒自己: 明年 _modulus default 要设成小一点的数字... 04/10 23:46