如何在 VB6 中声明 MAX_DOUBLE?
根据VB6的MSDN帮助
浮点值可以表示为 mmmEeee 或 mmmDeee,其中 mmm 是尾数,eee 是指数(10 的幂)。 Single 数据类型的最大正值为 3.402823E+38,即 3.4 乘以 10 的 38 次方; Double 数据类型的最大正值是 1.79769313486232D+308,即大约 1.8 乘以 10 的 308 次方。 使用 D 分隔数字文字中的尾数和指数会导致该值被视为 Double 数据类型。 同样,以相同的方式使用 E 会将值视为单一数据类型。
现在,在 VB6 IDE 中,我尝试输入此内容
const MAX_DOUBLE as Double = 1.79769313486232D+308
,但是,一旦我离开该行,IDE 就会抛出错误 6(溢出)
当您尝试进行的分配超出了分配目标的限制时,就会发生溢出。 ...
那么我如何定义 MAX_DOUBLE (和 MIN_DOUBLE )?
According to the MSDN help for VB6
Floating-point values can be expressed as mmmEeee or mmmDeee, in which mmm is the mantissa and eee is the exponent (a power of 10). The highest positive value of a Single data type is 3.402823E+38, or 3.4 times 10 to the 38th power; the highest positive value of a Double data type is 1.79769313486232D+308, or about 1.8 times 10 to the 308th power. Using D to separate the mantissa and exponent in a numeric literal causes the value to be treated as a Double data type. Likewise, using E in the same fashion treats the value as a Single data type.
Now in the VB6 IDE I've tried to enter this
const MAX_DOUBLE as Double = 1.79769313486232D+308
however, as soon as I move away from that line the IDE throws an Error 6 (Overflow)
An overflow results when you try to make an assignment that exceeds the limitations of the target of the assignment. ...
So how do I get MAX_DOUBLE (and MIN_DOUBLE for that matter) defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编辑:
解决了!
仔细检查二进制级别,这应该是你能达到的最高水平。 您可以继续添加 1 等值,但它会产生一个等于而不大于的数字。
输出是这样的:
01111111|11101111|11111111|11111111|11111111|11111111|11111111|11111111
这确实是 DoubleMax
Old:
您可以只使用 正无穷大。
Edit:
Solved it!
Double checked it down to the binary level, that should be as high as you can go. You can keep adding values like 1 etc but it yields a number equal to, not greater than.
Output is this:
01111111|11101111|11111111|11111111|11111111|11111111|11111111|11111111
Which is indeed DoubleMax
Old:
You could just use Positive infinity.
它必须是一个常量吗? 您可以通过使用 Byte 数组中的 CopyMemory 设置正确的位模式,将 MAX_DOUBLE 的准确值获取到变量中。
编辑:我忘了你还问过 MIN_DOUBLE,这更容易。
Does it have to be a Const? You can get the exact value of MAX_DOUBLE into a variable by setting the correct bit pattern using CopyMemory from a Byte array.
Edit: I forgot that you also asked about MIN_DOUBLE, which is even easier.
明显的实用解决方法:稍微减少数量。
我想这在大多数情况下就足够了。
Obvious pragmatic workaround: reduce the number slightly.
I imagine that'll be adequate in most situations.
使用“E”表示数字中的指数,而不是像下面这样的“D”。
[编辑]
看看下面的这个链接,滚动到底部。 这个具体的代码示例展示了如何使用这个构造。 希望这有帮助。
http://www.experts-exchange.com /Programming/Languages/.NET/Visual_Basic.NET/Q_22555684.html
Use an "E" for exponent in the number instead of a "D" like this below.
[edit]
Take a look at this link below, scroll to the bottom. This concrete code example shows how this construct is being employed. Hopefully this helps.
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22555684.html