pow example



    /** * @param int $cmixlev * * @return int|float|string|false */
    public static function centerMixLevelLookup($cmixlev) {
        static $centerMixLevelLookup;
        if (empty($centerMixLevelLookup)) {
            $centerMixLevelLookup = array(
                0 => pow(2, -3.0 / 6), // 0.707 (-3.0 dB)                 1 => pow(2, -4.5 / 6), // 0.595 (-4.5 dB)                 2 => pow(2, -6.0 / 6), // 0.500 (-6.0 dB)                 3 => 'reserved'
            );
        }
        return (isset($centerMixLevelLookup[$cmixlev]) ? $centerMixLevelLookup[$cmixlev] : false);
    }

    /** * @param int $surmixlev * * @return int|float|string|false */
return $constraints;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::fieldSettingsForm($form$form_state);
    $settings = $this->getSettings();

    $element['min']['#step'] = pow(0.1, $settings['scale']);
    $element['max']['#step'] = pow(0.1, $settings['scale']);

    return $element;
  }

  /** * {@inheritdoc} */
  public function preSave() {
    $this->value = round($this->value, $this->getSetting('scale'));
  }

  

  public static function toNumber($size): float {
    // Remove the non-unit characters from the size.     $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
    // Remove the non-numeric characters from the size.     $size = preg_replace('/[^0-9\.]/', '', $size);
    if ($unit) {
      // Find the position of the unit in the ordered string which is the power       // of magnitude to multiply a kilobyte by.       return round($size * pow(self::KILOBYTE, stripos('bkmgtpezy', $unit[0])));
    }
    else {
      // Ensure size is a proper number type.       return round((float) $size);
    }
  }

  /** * Validate that a string is a representation of a number of bytes. * * @param string $string * The string to validate. * * @return bool * TRUE if the string is valid, FALSE otherwise. */
return $element;
  }

  /** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $settings = $field_definition->getSettings();
    $precision = rand(10, 32);
    $scale = rand(0, 2);
    $max = is_numeric($settings['max']) ? $settings['max'] : pow(10, ($precision - $scale)) - 1;
    $min = is_numeric($settings['min']) ? $settings['min'] : -pow(10, ($precision - $scale)) + 1;
    // @see "Example #1 Calculate a random floating-point number" in     // http://php.net/manual/function.mt-getrandmax.php     $random_decimal = $min + mt_rand() / mt_getrandmax() * ($max - $min);
    $values['value'] = self::truncateDecimal($random_decimal$scale);
    return $values;
  }

}
/** * Tests default formatter behavior. */
  public function testNumberFormatter() {
    $type = mb_strtolower($this->randomMachineName());
    $float_field = mb_strtolower($this->randomMachineName());
    $integer_field = mb_strtolower($this->randomMachineName());
    $thousand_separators = ['', '.', ',', ' ', chr(8201), "'"];
    $decimal_separators = ['.', ','];
    $prefix = $this->randomMachineName();
    $suffix = $this->randomMachineName();
    $random_float = rand(0, pow(10, 6));
    $random_integer = rand(0, pow(10, 6));
    $assert_session = $this->assertSession();

    // Create a content type containing float and integer fields.     $this->drupalCreateContentType(['type' => $type]);

    FieldStorageConfig::create([
      'field_name' => $float_field,
      'entity_type' => 'node',
      'type' => 'float',
    ])->save();

    
--$precision;
            }
        }

        if (!is_int($precision) || $precision < 1 || $precision > 9) {
            throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
        }

        $this->_fractional += $milli;

        // Add/sub milliseconds + add/sub seconds         $max = pow(10, $this->_precision);
        // Milli includes seconds         if ($this->_fractional >= $max) {
            while ($this->_fractional >= $max) {
                $this->addSecond(1);
                $this->_fractional -= $max;
            }
        }

        if ($this->_fractional < 0) {
            while ($this->_fractional < 0) {
                $this->subSecond(1);
                
/** * Tests updating with expressions. */
  public function testExpressionUpdate() {
    // Ensure that expressions are handled properly. This should set every     // record's age to a square of itself.     $num_rows = $this->connection->update('test')
      ->expression('age', '[age] * [age]')
      ->execute();
    $this->assertSame(4, $num_rows, 'Updated 4 records.');

    $saved_name = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => pow(26, 2)])->fetchField();
    $this->assertSame('Paul', $saved_name, 'Successfully updated values using an algebraic expression.');
  }

  /** * Tests return value on update. */
  public function testUpdateAffectedRows() {
    // At 5am in the morning, all band members but those with a priority 1 task     // are sleeping. So we set their tasks to 'sleep'. 5 records match the     // condition and therefore are affected by the query, even though two of     // them actually don't have to be changed because their value was already
 elseif ($value < 0xFFFCCCCCCCCCCCC >> 40) {
            $i = 1;
        } elseif ($value < 0xFFFCCCCCCCCCCCC >> 30) {
            $i = 2;
        } elseif ($value < 0xFFFCCCCCCCCCCCC >> 20) {
            $i = 3;
        } else {
            $i = 4;
        }

        if ($i) {
            $value = $value / \pow(1024, $i);
        }

        if ($negative) {
            $value *= -1;
        }

        return [
            'value' => \round($value, 1),
            'unit' => $unit[$i],
        ];
    }

    
public static $defaultScale;
    public static $defaultPrecision;


    public static function Add($op1$op2$scale = null)
    {
        if ($scale === null) {
            $scale     = Zend_Locale_Math_PhpMath::$defaultScale;
            $precision = Zend_Locale_Math_PhpMath::$defaultPrecision;
        } else {
            $precision = pow(10, -$scale);
        }

        if (empty($op1)) {
            $op1 = 0;
        }
        $op1 = self::normalize($op1);
        $op2 = self::normalize($op2);
        $result = $op1 + $op2;
        if (is_infinite($result)  or  (abs($result - $op2 - $op1) > $precision)) {
            throw new Zend_Locale_Math_Exception("addition overflow: $op1 + $op2 != $result", $op1$op2$result);
        }

        

  public function providerTestCommonFormatSize() {
    $kb = Bytes::KILOBYTE;
    return [
      ['0 bytes', 0],
      ['1 byte', 1],
      ['-1 bytes', -1],
      ['2 bytes', 2],
      ['-2 bytes', -2],
      ['1023 bytes', $kb - 1],
      ['1 KB', $kb],
      ['1 MB', pow($kb, 2)],
      ['1 GB', pow($kb, 3)],
      ['1 TB', pow($kb, 4)],
      ['1 PB', pow($kb, 5)],
      ['1 EB', pow($kb, 6)],
      ['1 ZB', pow($kb, 7)],
      ['1 YB', pow($kb, 8)],
      ['1024 YB', pow($kb, 9)],
      // Rounded to 1 MB - not 1000 or 1024 kilobytes       ['1 MB', ($kb * $kb) - 1],
      ['-1 MB', -(($kb * $kb) - 1)],
      // Decimal Megabytes

  public function providerTestToNumber(): array {
    return [
      ['1', 1.0],
      ['1 byte', 1.0],
      ['1 KB'  , (float) Bytes::KILOBYTE],
      ['1 MB'  , (float) pow(Bytes::KILOBYTE, 2)],
      ['1 GB'  , (float) pow(Bytes::KILOBYTE, 3)],
      ['1 TB'  , (float) pow(Bytes::KILOBYTE, 4)],
      ['1 PB'  , (float) pow(Bytes::KILOBYTE, 5)],
      ['1 EB'  , (float) pow(Bytes::KILOBYTE, 6)],
      // Zettabytes and yottabytes cannot be represented by integers on 64-bit       // systems, so pow() returns a float.       ['1 ZB'  , pow(Bytes::KILOBYTE, 7)],
      ['1 YB'  , pow(Bytes::KILOBYTE, 8)],
      ['23476892 bytes', 23476892.0],
      // 76 MB.       ['76MRandomStringThatShouldBeIgnoredByParseSize.', 79691776.0],
      

  private static function computeSurplusScore(HTMLRestrictions $surplus, HTMLRestrictions $needed): int {
    // Compute a score for surplus elements, while taking into account how much     // impact each surplus element has:     $surplus_score = 0;
    foreach ($surplus->getAllowedElements() as $tag_name => $attributes_config) {
      // 10^6 per surplus tag.       if (!isset($needed->getAllowedElements()[$tag_name])) {
        $surplus_score += pow(10, 6);
      }

      // 10^5 per surplus "any attributes allowed".       if ($attributes_config === TRUE) {
        $surplus_score += pow(10, 5);
      }

      if (!is_array($attributes_config)) {
        continue;
      }

      
$field_settings = $this->getFieldSettings();

    $element += [
      '#type' => 'number',
      '#default_value' => $value,
      '#placeholder' => $this->getSetting('placeholder'),
    ];

    // Set the step for floating point and decimal numbers.     switch ($this->fieldDefinition->getType()) {
      case 'decimal':
        $element['#step'] = pow(0.1, $field_settings['scale']);
        break;

      case 'float':
        $element['#step'] = 'any';
        break;
    }

    // Set minimum and maximum.     if (is_numeric($field_settings['min'])) {
      $element['#min'] = $field_settings['min'];
    }
    

  protected function assertColorsAreEqual(array $expected, array $actual, int $tolerance, string $message = ''): void {
    // Fully transparent colors are equal, regardless of RGB.     if ($actual[3] == 127 && $expected[3] == 127) {
      return;
    }
    $distance = pow(($actual[0] - $expected[0]), 2) + pow(($actual[1] - $expected[1]), 2) + pow(($actual[2] - $expected[2]), 2) + pow(($actual[3] - $expected[3]), 2);
    $this->assertLessThanOrEqual($tolerance$distance$message . " - Actual: {" . implode(',', $actual) . "}, Expected: {" . implode(',', $expected) . "}, Distance: " . $distance . ", Tolerance: " . $tolerance);
  }

  /** * Function for finding a pixel's RGBa values. */
  public function getPixelColor(ImageInterface $image, int $x, int $y): array {
    $toolkit = $image->getToolkit();
    $color_index = imagecolorat($toolkit->getResource()$x$y);

    $transparent_index = imagecolortransparent($toolkit->getResource());
    

  public static function validStep($value$step$offset = 0.0) {
    $double_value = (double) abs($value - $offset);

    // The fractional part of a double has 53 bits. The greatest number that     // could be represented with that is 2^53. If the given value is even bigger     // than $step * 2^53, then dividing by $step will result in a very small     // remainder. Since that remainder can't even be represented with a single     // precision float the following computation of the remainder makes no sense     // and we can safely ignore it instead.     if ($double_value / pow(2.0, 53) > $step) {
      return TRUE;
    }

    // Now compute that remainder of a division by $step.     $remainder = (double) abs($double_value - $step * round($double_value / $step));

    // $remainder is a double precision floating point number. Remainders that     // can't be represented with single precision floats are acceptable. The     // fractional part of a float has 24 bits. That means remainders smaller than     // $step * 2^-24 are acceptable.     $computed_acceptable_error = (double) ($step / pow(2.0, 24));

    
Home | Imprint | This part of the site doesn't use cookies.