wp_exif_frac2dec

The timeline below displays how wordpress function wp_exif_frac2dec has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Converts a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str Fraction string.
 * @return int|float Returns calculated fraction or integer 0 on invalid input.
 */
function wp_exif_frac2dec($str)
{
    if (!is_scalar($str) || is_bool($str)) {
        return 0;
    }
    if (!is_string($str)) {
        return $str;
        // This can only be an integer or float, so this is fine.
    }
    // Fractions passed as a string must contain a single `/`.
    if (substr_count($str, '/') !== 1) {
        if (is_numeric($str)) {
            return (float) $str;
        }
        return 0;
    }
    list($numerator, $denominator) = explode('/', $str);
    // Both the numerator and the denominator must be numbers.
    if (!is_numeric($numerator) || !is_numeric($denominator)) {
        return 0;
    }
    // The denominator must not be zero.
    if (0 == $denominator) {
        // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- Deliberate loose comparison.
        return 0;
    }
    return $numerator / $denominator;
}

WordPress Version: 6.1

/**
 * Converts a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str Fraction string.
 * @return int|float Returns calculated fraction or integer 0 on invalid input.
 */
function wp_exif_frac2dec($str)
{
    if (!is_scalar($str) || is_bool($str)) {
        return 0;
    }
    if (!is_string($str)) {
        return $str;
        // This can only be an integer or float, so this is fine.
    }
    // Fractions passed as a string must contain a single `/`.
    if (substr_count($str, '/') !== 1) {
        if (is_numeric($str)) {
            return (float) $str;
        }
        return 0;
    }
    list($numerator, $denominator) = explode('/', $str);
    // Both the numerator and the denominator must be numbers.
    if (!is_numeric($numerator) || !is_numeric($denominator)) {
        return 0;
    }
    // The denominator must not be zero.
    if (0 == $denominator) {
        // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
        return 0;
    }
    return $numerator / $denominator;
}

WordPress Version: 5.9

/**
 * Convert a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str Fraction string.
 * @return int|float Returns calculated fraction or integer 0 on invalid input.
 */
function wp_exif_frac2dec($str)
{
    if (!is_scalar($str) || is_bool($str)) {
        return 0;
    }
    if (!is_string($str)) {
        return $str;
        // This can only be an integer or float, so this is fine.
    }
    // Fractions passed as a string must contain a single `/`.
    if (substr_count($str, '/') !== 1) {
        if (is_numeric($str)) {
            return (float) $str;
        }
        return 0;
    }
    list($numerator, $denominator) = explode('/', $str);
    // Both the numerator and the denominator must be numbers.
    if (!is_numeric($numerator) || !is_numeric($denominator)) {
        return 0;
    }
    // The denominator must not be zero.
    if (0 == $denominator) {
        // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
        return 0;
    }
    return $numerator / $denominator;
}

WordPress Version: 5.4

/**
 * Convert a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str
 * @return int|float
 */
function wp_exif_frac2dec($str)
{
    if (false === strpos($str, '/')) {
        return $str;
    }
    list($numerator, $denominator) = explode('/', $str);
    if (!empty($denominator)) {
        return $numerator / $denominator;
    }
    return $str;
}

WordPress Version: 5.3

/**
 * Convert a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str
 * @return int|float
 */
function wp_exif_frac2dec($str)
{
    if (false === strpos($str, '/')) {
        return $str;
    }
    list($n, $d) = explode('/', $str);
    if (!empty($d)) {
        return $n / $d;
    }
    return $str;
}

WordPress Version: 3.7

/**
 * Convert a fraction string to a decimal.
 *
 * @since 2.5.0
 *
 * @param string $str
 * @return int|float
 */
function wp_exif_frac2dec($str)
{
    @list($n, $d) = explode('/', $str);
    if (!empty($d)) {
        return $n / $d;
    }
    return $str;
}