Skip to content

printf() can strip sign of -INF #15964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
divinity76 opened this issue Sep 20, 2024 · 3 comments
Closed

printf() can strip sign of -INF #15964

divinity76 opened this issue Sep 20, 2024 · 3 comments

Comments

@divinity76
Copy link
Contributor

Description

The following code:

<?php
var_dump(sprintf("%.17g", -INF));

Resulted in this output:

string(3) "INF"

But I expected this output instead:

string(4) "-INF"

PHP Version

PHP 8.3.11

Operating System

Ubuntu 24.04

@divinity76 divinity76 changed the title sprintf %.17g negative infinty bug sprintf %.17g negative infinity bug Sep 20, 2024
@divinity76
Copy link
Contributor Author

duplicate of #9209

@divinity76 divinity76 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2024
@cmb69
Copy link
Member

cmb69 commented Sep 20, 2024

duplicate of #9209

Nope, not really. That is about truncation of INF due to very low precision, but the reported issue here is about loosing the minus sign.

@cmb69
Copy link
Member

cmb69 commented Sep 20, 2024

Also note that the problem is not particularly related to the precision, see https://3v4l.org/3F8nm. The only case where the minus sign would properly be retained is for padding="0", e.g. printf("%06g", -INF);, but that apparently looses the "I". Having had more test cases could have helped.

@cmb69 cmb69 changed the title sprintf %.17g negative infinity bug printf() can strip sign of -INF Dec 2, 2024
@cmb69 cmb69 closed this as completed in c2d3734 Dec 2, 2024
cmb69 added a commit that referenced this issue Dec 2, 2024
* PHP-8.4:
  Fix GH-15964: printf() can strip sign of -INF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants