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. 帕斯卡到C#转换
- 8. 帕斯卡三角SML
- 9. 帮助帕斯卡三角
- 10. 图像处理帕斯卡
- 11. 帕斯卡范围溢出
- 12. 计算以帕斯卡
- 13. 约帕斯卡输出
- 14. 链表帕斯卡尔
- 15. Exercice与帕斯卡尔
- 16. 帕斯卡计划练习
- 17. 帕斯卡进展状态
- 18. 帕斯卡长度+圆?
- 19. 算法smbPitchShift(帕斯卡尔)
- 20. 字符串数组在帕斯卡尔
- 21. 检查是否填充了预定义大小的数组 - 帕斯卡尔
- 22. 帕斯卡 - 阵列的大小
- 23. 帕斯卡尔布尔返回值?
- 24. 递归帕斯卡的三角形(Python)
- 25. 德尔福/帕斯卡尔例
- 26. 帕斯卡三角对角线在PHP
- 27. 检查输入字符 - 帕斯卡尔
- 28. 摘要功能帕斯卡尔
- 29. 帕斯卡三角形溶液
- 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