浮点运算总和不动

嗯,好的坏的和丑的
为什么round(cargof)留在那里2

uses crt;

type 
    trail_type = (blue ,desert ,white);
    fruit_class = (none ,apple ,pineapple);
type
    ontherun = Record
    trail : trail_type;
    cargo : Integer;
    miles : Integer;
end;
Var 
    b : File of ontherun;
    rec : ontherun;
    rec_b : array[1..3] of ontherun;
    k , cargo , load , xload , miles , run : Integer;
    cargof  : Double;
    fruit : fruit_class;

begin
        cargof := 0;
        Repeat
            cargof := 0.04*cargof + 2.0;
            Writeln(round(cargof)); 
        Until cargof > 223;
writeln('hi');  
end.

回答

实际上,这与 FreePascal 没有任何关系。而不是帕斯卡。而不是浮点数。而不是计算机编程。连电脑都没有。

这是纯数学。

我们有递归关系a (0) = 0, a ( n + 1) = (1/25) a ( n ) + 2。

与 ansatz a ( n ) = ? + ? k ^ n我们发现a ( n + 1) = ? + ? k ^( n + 1) = ? + ? k k ^ n = ? + k ( a ( n ) ? ?) = ? ? ķ?+ k a ( n ) 因为a ( n ) ? ? = ? k ^ n。对于所有非负值,这应该等于 2 + (1/25) a ( n ) ñ,这意味着k = 1/25 和 ? ? ķ?= 2 这意味着 ? = 25/12。最后,a (0) = 0 产生 ? = 25/12。

因此,对于所有非负na ( n ) = (25/12) (1 ? 1/25^ n ) 。

很容易验证这确实是一个解决方案,并且a ( n ) ? 25/12 作为n ? ?; 具体来说,a ( n ) 单调增长到此限制。

现在,25/12 = 2.08333333333……所以四舍五入到最接近的整数值永远不会超过 2。


以上是浮点运算总和不动的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>