Differences Between: [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; 4 5 use PhpOffice\PhpSpreadsheet\Calculation\Exception; 6 use PhpOffice\PhpSpreadsheet\Calculation\Functions; 7 8 class BesselY 9 { 10 /** 11 * BESSELY. 12 * 13 * Returns the Bessel function, which is also called the Weber function or the Neumann function. 14 * 15 * Excel Function: 16 * BESSELY(x,ord) 17 * 18 * @param mixed $x A float value at which to evaluate the function. 19 * If x is nonnumeric, BESSELY returns the #VALUE! error value. 20 * @param mixed $ord The integer order of the Bessel function. 21 * If ord is not an integer, it is truncated. 22 * If $ord is nonnumeric, BESSELY returns the #VALUE! error value. 23 * If $ord < 0, BESSELY returns the #NUM! error value. 24 * 25 * @return float|string Result, or a string containing an error 26 */ 27 public static function BESSELY($x, $ord) 28 { 29 $x = Functions::flattenSingleValue($x); 30 $ord = Functions::flattenSingleValue($ord); 31 32 try { 33 $x = EngineeringValidations::validateFloat($x); 34 $ord = EngineeringValidations::validateInt($ord); 35 } catch (Exception $e) { 36 return $e->getMessage(); 37 } 38 39 if (($ord < 0) || ($x <= 0.0)) { 40 return Functions::NAN(); 41 } 42 43 $fBy = self::calculate($x, $ord); 44 45 return (is_nan($fBy)) ? Functions::NAN() : $fBy; 46 } 47 48 private static function calculate(float $x, int $ord): float 49 { 50 // special cases 51 switch ($ord) { 52 case 0: 53 return self::besselY0($x); 54 case 1: 55 return self::besselY1($x); 56 } 57 58 return self::besselY2($x, $ord); 59 } 60 61 private static function besselY0(float $x): float 62 { 63 if ($x < 8.0) { 64 $y = ($x * $x); 65 $ans1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * 66 (-86327.92757 + $y * 228.4622733)))); 67 $ans2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * 68 (47447.26470 + $y * (226.1030244 + $y)))); 69 70 return $ans1 / $ans2 + 0.636619772 * BesselJ::BESSELJ($x, 0) * log($x); 71 } 72 73 $z = 8.0 / $x; 74 $y = ($z * $z); 75 $xx = $x - 0.785398164; 76 $ans1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6))); 77 $ans2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * 78 (-0.934945152e-7)))); 79 80 return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2); 81 } 82 83 private static function besselY1(float $x): float 84 { 85 if ($x < 8.0) { 86 $y = ($x * $x); 87 $ans1 = $x * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * 88 (0.7349264551e9 + $y * (-0.4237922726e7 + $y * 0.8511937935e4))))); 89 $ans2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y * 90 (0.1020426050e6 + $y * (0.3549632885e3 + $y))))); 91 92 return ($ans1 / $ans2) + 0.636619772 * (BesselJ::BESSELJ($x, 1) * log($x) - 1 / $x); 93 } 94 95 $z = 8.0 / $x; 96 $y = $z * $z; 97 $xx = $x - 2.356194491; 98 $ans1 = 1.0 + $y * (0.183105e-2 + $y * (-0.3516396496e-4 + $y * (0.2457520174e-5 + $y * (-0.240337019e-6)))); 99 $ans2 = 0.04687499995 + $y * (-0.2002690873e-3 + $y * (0.8449199096e-5 + $y * 100 (-0.88228987e-6 + $y * 0.105787412e-6))); 101 102 return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2); 103 } 104 105 private static function besselY2(float $x, int $ord): float 106 { 107 $fTox = 2.0 / $x; 108 $fBym = self::besselY0($x); 109 $fBy = self::besselY1($x); 110 for ($n = 1; $n < $ord; ++$n) { 111 $fByp = $n * $fTox * $fBy - $fBym; 112 $fBym = $fBy; 113 $fBy = $fByp; 114 } 115 116 return $fBy; 117 } 118 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body