加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp-classic – ASP Classic中的溢出

发布时间:2020-12-16 06:56:29 所属栏目:asp.Net 来源:网络整理
导读:我想知道是否有人可以帮助我,因为我已经对我认为是一个简单错误的简单原因视而不见. 我有这个代码: doRound1(x1) denom1 = 5 y1 = denom1 - x1 mod denom1 if y1 denom1 then x1= x1+y1 end if doRound1=x1 End function 'theCalc = 20488888888.684 theCal
我想知道是否有人可以帮助我,因为我已经对我认为是一个简单错误的简单原因视而不见.

我有这个代码:

doRound1(x1)
  denom1 = 5
  y1 = denom1 - x1 mod denom1
  if y1 <> denom1 then
    x1= x1+y1
  end if

  doRound1=x1
 End function

 'theCalc = 20488888888.684
  theCalc = cDbl(22222222221) * 1.844
  doRound1(theCalc)

我收到这个错误

Microsoft VBScript runtime  error '800a0006'
Overflow: 'x1'

在上面的代码中由此行引起:

y1 = denom1 - x1 mod denom1

有任何想法吗?就像我说的那样,我今晚已经失明了.

解决方法

答案似乎是在 PRB: “Overflow” with Integer Division and MOD Operator:

The Visual Basic Help topic for the
Mod operator and the integer division
operator () explains that if floating
point numbers are used in the
expression,they are converted to
Longs first. Thus,if the floating
point number is greater than the
maximum value of a Long
(2,147,483,647),or less than the
minimum value for a long
(-2,648),an overflow error
will occur.

答案也在那里提供:

The following code demonstrates how to
perform integer division and modulo
arithmetic when the size of an operand
is sufficiently large to cause
overflow:

Dim dblX as Double
Dim dblY as Double
dblX = 2147483648                ' numerator
dblY = 123                       ' denominator

' round off the numerator and denominator (ensure number is .0)
dblX = INT(dblX + .5)         
dblY = INT(dblY + .5)      

' Emulate integer division
MsgBox FIX(dblX / dblY)             
' Emulate modulo arithmetic
MsgBox dblX - ( dblY * FIX(dblX / dblY) )

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读