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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。