Skip to content
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

Fix printf-family functions on long double inf #1273

Merged
merged 1 commit into from
Sep 1, 2024

Conversation

GabrielRavier
Copy link
Collaborator

@GabrielRavier GabrielRavier commented Sep 1, 2024

Cosmopolitan's printf-family functions currently very poorly handle being passed a long double infinity.

For instance, a program such as:

#include <stdio.h>

int main()
{
    printf("%f\n", 1.0 / 0.0);
    printf("%Lf\n", 1.0L / 0.0L);
    printf("%e\n", 1.0 / 0.0);
    printf("%Le\n", 1.0L / 0.0L);
    printf("%g\n", 1.0 / 0.0);
    printf("%Lg\n", 1.0L / 0.0L);
}

will currently output the following:

inf
0.000000[followed by 32763 more zeros]
inf
N.aN0000e-32769
inf
N.aNe-32769

when the correct expected output would be:

inf
inf
inf
inf
inf
inf

This patch fixes this, and adds tests for the behavior.

@github-actions github-actions bot added the libc label Sep 1, 2024
Cosmopolitan's printf-family functions currently very poorly handle
being passed a long double infinity.

For instance, a program such as:

 #include <stdio.h>

int main()
{
    printf("%f\n", 1.0 / 0.0);
    printf("%Lf\n", 1.0L / 0.0L);
    printf("%e\n", 1.0 / 0.0);
    printf("%Le\n", 1.0L / 0.0L);
    printf("%g\n", 1.0 / 0.0);
    printf("%Lg\n", 1.0L / 0.0L);
}

will currently output the following:

inf
0.000000[followed by 32763 more zeros]
inf
N.aN0000e-32769
inf
N.aNe-32769

when the correct expected output would be:

inf
inf
inf
inf
inf
inf

This patch fixes this, and adds tests for the behavior.
@GabrielRavier GabrielRavier force-pushed the fix/printf-long-double-inf branch from ecc831a to a4bcba8 Compare September 1, 2024 15:07
Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks!

@jart jart merged commit 75e161b into jart:master Sep 1, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants