Skip to content

printf() can strip sign of -INF #15964

Closed
Closed

Description

@divinity76

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

Activity

  1. changed the title [-]sprintf %.17g negative infinty bug[/-] [+]sprintf %.17g negative infinity bug[/+] on Sep 20, 2024
  2. divinity76 commented on Sep 20, 2024

    @divinity76
    ContributorAuthor

    duplicate of #9209

  3. cmb69 commented on Sep 20, 2024

    @cmb69
    Member

    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.

  4. reopened this on Sep 20, 2024
  5. cmb69 commented on Sep 20, 2024

    @cmb69
    Member

    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.

  6. changed the title [-]sprintf %.17g negative infinity bug[/-] [+]printf() can strip sign of -INF[/+] on Dec 2, 2024
  7. added a commit that references this issue on Dec 2, 2024
    c2d3734
  8. added a commit that references this issue on Dec 2, 2024
    3b517e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions