PHP 4.0 Bug #6547 Updated: Maths calculation problem

From: Date: Wed, 06 Sep 2000 16:55:09 +0000
Subject: PHP 4.0 Bug #6547 Updated: Maths calculation problem
Groups: php.dev 
Request: Send a blank email to php-dev+get-32404@lists.php.net to get a copy of this message
ID: 6547 Updated by: stas Reported By: pp.foong@net-linx.com.my Status: Feedback Bug Type: Scripting Engine problem Assigned To: Comments: Could you please cut down you code and provide example for only the statement that does not work? Previous Comments: [2000-09-05 06:14:57] pp.foong@net-linx.com.my The function below will show the sunrise or sunset time of the day $yday for a place based on its latitude and longitude information. It works well with php3.x and php4.x until 4.0.1pl2, but in php4.0.2, it will give the same result for all sunrise and sunset and whatever latitude and longitude information passed to it. Some calculating function might not function well in the version of php... ========================================================== function suntime ($latitude, $longitude, $timezone, $yday) { $A = 1.5708; $B = 3.14159; $C = 4.71239; $D = 6.28319; $E = 0.0174533 * $latitude; $F = 0.0174533 * $longitude; $G = 0.261799 * $timezone; $R = -.0145439; for ($i = 0; $i < 2; $i++) { if (!$i) {$J = $A; $type = "rise";} else {$J = $C; $type = "set"; } $K = $yday + (($J - $F) / $D); $L = ($K * .017202) - .0574039; // Solar Mean Anomoly $M = $L + .0334405 * sin($L); // Solar True Longitude $M += 4.93289 + (3.49066E-04) * sin(2 * $L); // Quadrant Determination if ($D == 0) {exit;} while ($M < 0) {$M = ($M + $D);} while ($M >= $D) {$M = ($M - $D);} if (($M / $A) - intval($M / $A) == 0) {$M += 4.84814E-06;} $P = sin($M) / cos($M); // Solar Right Ascension $P = atan2(.91746 * $P, 1); // Quadrant Adjustment if ($M > $C) {$P += $D;} else {if ($M > $A) {$P += $B;} } $Q = .39782 * sin($M); // Solar Declination $Q = $Q / sqrt(-$Q * $Q + 1); $Q = atan2($Q, 1); $S = $R - (sin($Q) * sin($E)); $S = $S / (cos($Q) * cos($E)); if (abs($S) > 1) {echo 'none';} // Null phenomenon $S = $S / sqrt(-$S * $S + 1); $S = $A - atan2($S, 1); if ($type == 'rise') {$S = $D - $S ;} $T = $S + $P - 0.0172028 * $K - 1.73364; // Local apparent time $U = $T - $F; // Universal timer $V = $U + $G; // Wall clock time // Quadrant Determination if ($D == 0) {exit;} while ($V < 0) {$V = ($V + $D);} while ($V >= $D) {$V = ($V - $D);} $V = $V * 3.81972; $hour = intval($V); $min = intval((($V - $hour) * 60) + 0.5); echo "<font size="1" color="#ff0000">sun$type: "; echo date( "g:i A", mktime($hour,$min,0,$mon,$mday,$year) ); echo "</font><br>"; } } =========================================================== --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=6547

« previous php.dev (#32404) next »