douminfu8033 2011-03-01 23:47
浏览 110
已采纳

php sqrt函数返回一个整数?

I'm creating a simple PHP program that does an action if (and only if) three random numbers compute to an integer. The random numbers are all integers, created with the rand() function. Without going into the specific details of the computation, the important thing (in terms of my problem) is that it includes the taking of a square root. Not being a very experienced PHP coder, the only square root function I know is sqrt(). The problem is, sqrt() returns a float, even when the input is an integer and output is exact. I briefly thought about converting the output to an integer (using something like intval(), but that won't work because that will convert all outputs to integers, making the test useless! Any ideas on how to do this? Thanks,

  • 写回答

5条回答 默认 最新

  • doucai6663 2011-03-01 23:52
    关注

    If you just want to determine if it is a perfect square, just determine if the

    intval(result) * intval(result) == originalValue
    

    I don't know the php version of those functions, but perhaps you do? :)

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!