Ответов: 67 Просмотров: 4256
|
EuGen пишет:Урок № 5. Математические функции
0. Вернет true, если принять, что такие числа допустимы. Если читатель знает предмет вопроса (или не поленился заглянуть в википедию), то он знает, что трансцедентные числа - обычные вещественные числа. Но являются они корнями многочлена с иррациональными коэффициентами. Единственное что - их представление в типе float языка php сделает их уже не трансцентными вовсе. Так что - с точки зрения float функция is_nan вернет true. Если же считать, что трансцедентные числа нельзя записать представлением float, то и вообще ничего не вернет (агрумента то и не будет)
1.
PHP:
скопировать код в буфер обмена
<?PHP class Converter { protected $cipherSet; protected $rgCiphers; protected $inputSet; protected $outputSet; protected $fromBase; protected $toBase; protected $iErrorCode; protected $sErrorMessage; /*Submit only full cipher set*/ function __construct($strSet) { $this->cipherSet=$strSet; $this->iErrorCode=0; $this->sErrorMessage=""; } /*multiplication with non-decimal base*/ protected function baseArithmeticMult($num) { $currentResultLen=count($this->rgCiphers); if ($currentResultLen==0) { return; } $currentPos=0; $div=0; do { $divided=0; if ($currentResultLen>$currentPos) { $divided=$this->rgCiphers[$currentPos]*$num; } $divided+=$div; $rgMods[$currentPos]=$divided%$this->toBase; $div=(int)($divided/$this->toBase); $currentPos++; } while($currentResultLen>$currentPos||$div!=0); $this->rgCiphers=$rgMods; } /*addition with non-decimal base*/ protected function baseArithmeticPlus($num) { $currentPos=0; $divided=$num; do { $divided+=(int)($this->rgCiphers[$currentPos]); $this->rgCiphers[$currentPos]=$divided%$this->toBase; $divided=(int)($divided/$this->toBase); $currentPos++; } while ($buf>0); } /*error's getters*/ public function getErrorCode() { return $this->iErrorCode; } public function getErrorMessage() { return $this->sErrorMessage; } /*main function*/ public function baseConvert($num, $fromBase=0, $toBase=0) { $num=(string)($num); $this->inputSet=substr($this->cipherSet, 0 , $fromBase); $this->outputSet=substr($this->cipherSet, 0 , $toBase); $this->toBase=$toBase; $this->rgCiphers=array(); for ($currentPos=0; $currentPos<$totalCiphers; $currentPos++) { $currentCipher=$num[$currentPos]; if($cipherSign==0) { $this->iErrorCode=255; $this->sErrorMessage="Cipher '".$currentCipher."' was not found in cipher set: ".$this->inputSet; return null; } elseif($cipherSign>1) { $this->iErrorCode=255; $this->sErrorMessage="Cipher '".$currentCipher."' was found more than once in cipher set: ".$this->inputSet; return null; } if ($currentPos!=0) { $this->baseArithmeticMult($fromBase); } $this->baseArithmeticPlus(strpos($this->inputSet, $currentCipher)); } $convertedNum=''; $totalCiphers=count($this->rgCiphers); for ($currentPos=0; $currentPos<$totalCiphers; $currentPos++) { $convertedNum=$this->outputSet[$this->rgCiphers[$currentPos]].$convertedNum; } return $convertedNum; } } ?>
2. Некоторые примеры:
is_nan(sqrt(-1)) и is_finite(sqrt(-1))
is_nan(acos(2)) и is_finite(acos(2))
Здравствуйте, спасибо за отличный сайт и кучи материала!
Я дошел до д/з 5 урока 2го задания сделал его кое как, но работает. Потом посмотрел решение - лучше бы я этого не делал. Я правильно понимаю что на 5м уроке я должен уметь писать подобного рода функцию, как в решении? Непонятно ничерта))
CODE ( htmlphp):
скопировать код в буфер обмена
$a=61; function convert($a) { if ($a<36){ echo $b; } elseif ($a<62) { $a=$a-26; } else { echo "введите число в диапазоне от 0 до 61"; } } echo convert($a);
|