数值溢出 [英] Numerical overflow

查看:72
本文介绍了数值溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Borland Builder 6,运行没有CodeGuard的小型

程序时出现数值溢出(exp:OVERFLOW error)。在运行期间激活CodeGuard时,程序确实没有给出任何错误消息。

导致溢出的等式使用exp函数,但给定和

结果值不是很大。那么为什么看起来好像在缓冲区中没有足够的空间?为什么不会出现问题,

当使用激活的CodeGuard运行相同的程序时?


公式如下所示(int delta_t除外) :所有变量

double):

new_amount = old_amount *(1 - (A * exp(K1 * delta_t)+(1-A)*

exp(K2 * delta_t)));


参数的值为:

A:0到0.6之间

K1:介于-10 ^( - 1)和-10 ^( - 4)之间

K2:介于-3和-10(-5)之间

delta_t :1到可能几百,但程序永远不会达到delta_t的大值将发生的点。


问题不是由数据类型引起的:当所有

变量和常数1都加倍时,它也会出现。溢出发生在整个

范围的参数值上。可以点击错误消息,

程序将继续。但由于等式是在
a循环中写的,错误会反复出现,最终导致

程序崩溃。

Using Borland Builder 6, I get numerical overflow when running a small
programme without CodeGuard ("exp: OVERFLOW error"). The programme does
not give any error messages when CodeGuard is activated during the run.
The equation that causes overflow uses the exp-function, but given and
resulting values are not very large. So why does it seem as if there
were not enough space in the buffer? And why doesn''t the problem occur,
when the same programme is run with an activated CodeGuard?

The equation looks like this (except int delta_t: all variables
double):
new_amount = old_amount * ( 1 - ( A * exp(K1* delta_t) + (1-A) *
exp(K2* delta_t) ) );

The values of the parameters are:
A: between 0 and 0.6
K1: between -10^(-1) and -10^(-4)
K2: between -3 and -10(-5)
delta_t: 1 to possibly several hundred, but the programme never reaches
the point where large values of delta_t would occur.

The problem is not caused by data types: it also comes when all
variables and the constant 1 are double. Overflow occurs over the whole
range of parameter values. The error message can be clicked away, the
programme will then continue. But since the equation is written within
a loop, the error will come back repeatedly, finally causing the
programme to crash.

推荐答案



Parachute写道:

Parachute wrote:

使用Borland Builder 6,我得到数值溢出在没有CodeGuard的情况下运行一个小的
程序时(exp:OVERFLOW error)。在运行期间激活CodeGuard时,程序确实没有给出任何错误消息。

导致溢出的等式使用exp函数,但给定和

结果值不是很大。那么为什么看起来好像在缓冲区中没有足够的空间?为什么问题不会发生,

当使用激活的CodeGuard运行相同的程序时?
Using Borland Builder 6, I get numerical overflow when running a small
programme without CodeGuard ("exp: OVERFLOW error"). The programme does
not give any error messages when CodeGuard is activated during the run.
The equation that causes overflow uses the exp-function, but given and
resulting values are not very large. So why does it seem as if there
were not enough space in the buffer? And why doesn''t the problem occur,
when the same programme is run with an activated CodeGuard?



尝试将表达式分解为至少三个单独的

赋值语句,然后打印出值。

另外编写自己的exp()函数包装器,打印出传入的

和传出值。

try breaking down the expression into at least three separate
assignment statements, then print out the values.

ALso write your own exp() function wrapper, and print out the incoming
and outgoing values.




Ancient_Hacker schrieb:

Ancient_Hacker schrieb:

Parachute写道:
Parachute wrote:

使用Borland Builder 6,运行没有CodeGuard的小型
程序时出现数字溢出(exp:OVERFLOW error)。在运行期间激活CodeGuard时,程序确实没有给出任何错误消息。

导致溢出的等式使用exp函数,但给定和

结果值不是很大。那么为什么看起来好像在缓冲区中没有足够的空间?为什么问题不会发生,

当使用激活的CodeGuard运行相同的程序时?
Using Borland Builder 6, I get numerical overflow when running a small
programme without CodeGuard ("exp: OVERFLOW error"). The programme does
not give any error messages when CodeGuard is activated during the run.
The equation that causes overflow uses the exp-function, but given and
resulting values are not very large. So why does it seem as if there
were not enough space in the buffer? And why doesn''t the problem occur,
when the same programme is run with an activated CodeGuard?



尝试将表达式分解为至少三个单独的

赋值语句,然后打印出值。

另外编写自己的exp()函数包装器,并打印出传入的

和传出值。


try breaking down the expression into at least three separate
assignment statements, then print out the values.

ALso write your own exp() function wrapper, and print out the incoming
and outgoing values.



我发现了一个错误:它位于时间变量中,由于不正确,它经常使用非常奇怪的值在将新的时间值分配给变量之前使用动态内存

分配。所以,这个问题的根源离它的出现还很远......


非常感谢你的帮助!

Heidrun

I''ve found the mistake: it lay in the time-variable, which regularly
took very strange values due to an incorrect use of dynamic memory
allocation before assigning the new time-value to the variable. So, the
root of the problem lay quite far away from its emergence...

Many thanks for your help!
Heidrun


这篇关于数值溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆