[php-src] Issue #9209: precision 0 -INF
| From: | hormus | Date: | Sun, 31 Jul 2022 14:10:44 +0000 |
| Subject: | [php-src] Issue #9209: precision 0 -INF | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242089@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9209
Author: hormus
### Description
```php
<?php
ini_set('precision', 0);
ini_set('serialize_precision', 0);
$float = -INF;
$string = '';
if(is_float($float)) {
if(INF === INF && (INF == $float || -INF == $float || is_negative($float) &&
'INF' == substr((string) $float, 1))) {
$y = 'I';
$z = 'I';
if(is_negative($float)) {
$y = 'I';
$z = '-I';
}
$string = strtr('INF', array($y => $z));
} else {
$string = $float . '';
}
}
function is_negative($num) {
$sign = substr((string) $num, 0, 1);
if(45 == ord($sign)) {
return true;
} else {
return NULL;
}
}
$string2 = $float . '';
var_dump($string, $string2);
//php >= 7.1.0
ini_set('precision', -1);
ini_set('serialize_precision', -1);
if(is_float($float)) {
if(INF === INF && (INF == $float || -INF == $float || is_negative($float) &&
'INF' == substr((string) $float, 1))) {
$y = 'I';
$z = 'I';
if(is_negative($float)) {
$y = 'I';
$z = '-I';
}
$string = strtr('INF', array($y => $z));
} else {
$string = $float . '';
}
}
$string2 = $float . '';
var_dump($string, $string2);
?>
```
Correct without loose precision for special case INF, -INF or NAN
### PHP Version
php 8.1.7
### Operating System
Irrelevant