duanmu2013 2015-10-09 11:55
浏览 26
已采纳

没有PHP扩展的大数字(权力......)

<?php
$res = pow(5, pow(5, pow(5, pow(5, 5))));
echo $res;

Outputs :

INF

I know it cannot be stored in a 64 bit float, but is there a way to calculate this kind of big number ? All my attempts failed (always this "INF").

EDIT : Yes, I know that this number is huge, and that's really what I'm trying to calculate. Also, I'm trying to do it without extensions (unless I fully understand what the extension does and I'm able to code it myself).

  • 写回答

3条回答 默认 最新

  • drlnwji79147769 2015-10-09 12:03
    关注

    Edit: As noted in the comments, the GMP extension may work, and may be more suited to integer math.

    Another commenter suggested providing more information than links. The extensions noted in this and other answers are better-suited than the standard built-in php functions for either larger ints or more precise floating-point numbers.

    But... you may not be able to just chain the results together with gmp_pow the same way you did in the question. For one thing, you need php 5.6 to use a gmp number as the parameter for gmp_pow.

    For another thing, the number is so large, you might need to use gmp_powm, as explained in this answer

    Original Answer You could try BCMath extension although it may not be installed by default. (although BCMath may be better for working with floating points rather than Ints)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)