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

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

报告相同问题?