0
A
回答
3
在FreePascal的它在数学单元中实现:
operator ** (bas,expo : float) e: float; inline;
begin
e:=power(bas,expo);
end;
operator ** (bas,expo : int64) i: int64; inline;
begin
i:=round(intpower(bas,expo));
end;
function power(base,exponent : float) : float;
begin
if Exponent=0.0 then
result:=1.0
else if (base=0.0) and (exponent>0.0) then
result:=0.0
else if (abs(exponent)<=maxint) and (frac(exponent)=0.0) then
result:=intpower(base,trunc(exponent))
else if base>0.0 then
result:=exp(exponent * ln (base))
else
InvalidArgument;
end;
function intpower(base : float;const exponent : Integer) : float;
var
i : longint;
begin
if (base = 0.0) and (exponent = 0) then
result:=1
else
begin
i:=abs(exponent);
intpower:=1.0;
while i>0 do
begin
while (i and 1)=0 do
begin
i:=i shr 1;
base:=sqr(base);
end;
i:=i-1;
intpower:=intpower*base;
end;
if exponent<0 then
intpower:=1.0/intpower;
end;
end;
相关问题
- 1. 传递参数在帕斯卡定义
- 2. 零指针帕斯卡尔
- 3. 定义最大帕斯卡尔
- 4. 从帕斯卡
- 5. 在卡斯帕
- 6. 帕斯卡小数点
- 7. 帕斯卡,生成数字
- 8. 空指针异常帕斯卡三角
- 9. 帕斯卡到C:TRUNC
- 10. 帕斯卡三角
- 11. 帕斯卡汉译
- 12. 由帕斯卡尔
- 13. 指针指向帕斯卡指针阵列
- 14. 指定斯卡拉
- 15. Exercice与帕斯卡尔
- 16. 帕斯卡重复标识
- 17. 使用在帕斯卡
- 18. 帕斯卡进展状态
- 19. 帕斯卡长度+圆?
- 20. 帕斯卡三角SML
- 21. 约帕斯卡输出
- 22. 帕斯卡的理解
- 23. 帕斯卡到C#转换
- 24. Python - 帕斯卡三角形
- 25. 帕斯卡计划练习
- 26. 图像处理帕斯卡
- 27. 帕斯卡范围溢出
- 28. 帕斯卡内存问题
- 29. 算法smbPitchShift(帕斯卡尔)
- 30. 计算以帕斯卡
你说的定义是什么意思?这就是所谓的指数运算,可能使用平方和乘法方法或其一些变体来实现。 – Thomas 2013-03-13 04:09:45
大多数Pascal实现为Exp,Ln和Power提供标准函数。例如:http://www.freepascal.org/docs-html/rtl/math/power.html – paulsm4 2013-03-13 04:09:53
我一直在寻找Pascal如何实现它 – thesentyclimate413 2013-03-13 04:12:22