doula2426 2014-04-13 22:59
浏览 66
已采纳

PHP中的时间膨胀计算除以零?

After doing quite a bit of digging, I found the calculations to get time dilation in space based on velocity in marks of lightspeed in a vaccuum.

I am using the earth rotation base (will account for earth speed later), as the start number to up-convert into lightyear time.

The code I have written is as follows :

$now = (time() / 86164.098903691);

echo 'Days: ' . $now;
echo 'Lightspeed: ' . dilation(0.95, $now);


function dilation($lightspeed, $elapsed) {
    $t = $elapsed/(((1-($lightspeed*299792458)^2)/(299792458^2))^0.5);
    return $t;
}

Basically, the numbers are as follows :

  • 299792458 is the speed of light in a vaccum (m/second)

  • 86164.098903691 is the exact seconds for a complete rotation of the earth on it's axis (aka, one earth day -- not to be confused with solar days which fluctuate based on distance of the sun, and moon). Reference: International Earth Rotation and Reference Systems Service.

The formula is a conversion to php from here >> http://www.phy.olemiss.edu/HEP/QuarkNet/time.html << which seems to accurately represent time dilation based on velocity.

The problem I am having with this code is I get the following error ::

[Sun Apr 13 18:47:39.413743 2014] [:error] [pid 3028:tid 1328] [client 127.0.0.1:60754] PHP Warning:  Division by zero in C:\\server\\www\\127.0.0.1\\htdocs\\test.php on line 31

However it is not clear as to why as all variables seem to be accounted for. Could you please point out why (a solution) this is happening ?

Addendum

The following code does not return any errors --

$time = time(); $now = ($time / 86164.098903691);

$lightspeed = 0.95;
//echo ($lightspeed*299792458)^2;

$speed1 = (1-(($lightspeed*299792458)^2));
$speed2 = ((299792458^2)^0.5);
$dilation = ($now/($speed1/$speed2));

echo 'Unix: ' . $time . "
";
echo 'Days: ' . $now . "
";
echo 'Speed1: ' . $speed1 . "
";
echo 'Speed2: ' . $speed2 . "
";
echo 'Dilation: ' . $dilation . "
";
  • 写回答

1条回答 默认 最新

  • dqg63264 2014-04-13 23:12
    关注

    ^ is a bitwise xor operator in PHP, not an exponential operator

    use

    pow($lightspeed*299792458,2)
    

    and

    pow(299792458,2)
    

    instead

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题