gpt4 book ai didi

asp-classic - ASP Classic 中的溢出

转载 作者:行者123 更新时间:2023-12-04 19:23:50 30 4
gpt4 key购买 nike

我想知道是否有人可以帮助我,因为我对我认为导致简单错误的简单原因视而不见。

我有这个代码:

 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(11111111111) * 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,147,483,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) )

关于asp-classic - ASP Classic 中的溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1433360/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com