php / php/php-src

precision 0 -INF

Open
#9,209 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Category: Engine Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description
<?php

ini_set('precision', 0);
ini_set('serialize_precision', 0);
$nif = -INF;
$pif = INF;
$float = -INF;
$string = '';
if(is_float($float)) {
if(INF === INF) {
if($pif === $float) {
$string = 'INF';
} elseif($nif === $float) {
$string = '-INF';
} else {
$string = $float . '';
}
}
}
$error = '';
$string3 = $pif . '';
$arr = preg_split('//', $string3);
$count = count($arr) - 2;
$false = true;
foreach($arr as $key => $value) {
if($key > 0 && $key <= $count) {
$ord = ord($arr[$key]);
if(1 == $key) {
$y = 'I';
$z = 'i';
} elseif(2 == $key) {
$y = 'N';
$z = 'n';
} elseif(3 == $key) {
$y = 'F';
$z = 'f';
}
if(!($ord == ord($y) || $ord == ord($z))) {
$false = false;
break;
}
}
}
if(!($false && $pif === INF)) {
$error = $error . 'INF';
}
$string4 = $nif . '';
$arr2 = preg_split('//', $string4);
$count = count($arr2) - 2;
$false2 = true;
foreach($arr2 as $key2 => $value2) {
if($key2 > 0 && $key2 <= $count) {
$ord = ord($arr[$key2]);
if(1 == $key2) {
$y = '-';
$z = '-';
} elseif(2 == $key2) {
$y = 'I';
$z = 'i';
} elseif(3 == $key2) {
$y = 'N';
$z = 'n';
} elseif(4 == $key2) {
$y = 'F';
$z = 'f';
}
if(!($ord == ord($y) || $ord == ord($z))) {
$false2 = false;
break;
}
}
}

if(!($false2 && $nif === -INF)) {
$error = $error . '-INF';
}
if(!(INF === INF)) {
$error = $error . 'Not === INF';
}

$string2 = $float . '';
var_dump($string, $string2, $error);

?>

Correct:
string(4) "-INF" string(4) "-INF" string(0) ""
Correct without loose precision for special case INF, -INF or NAN.

PHP Version

php 8.1.7

Operating System

Irrelevant

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied PHP reproduction on PHP 8.1.7 and compare the string conversions of INF and -INF when precision and serialize_precision are set to 0. Trace the handling of these special floating-point values, then verify that the output matches the expected empty error string without loosening precision behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.