Skip to content

fixed #13606/#13607 - consistently print (precise) float as such in ValueFlow debug output #7274

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

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

firewave
Copy link
Collaborator

@firewave firewave commented Feb 1, 2025

No description provided.

@firewave
Copy link
Collaborator Author

firewave commented Feb 1, 2025

Okay. This appears to be a bit of a mess.

#include <iostream>
#include <string>

void print(double d)
{
    std::cout << std::to_string(d) << std::endl;
    printf("%f\n", d);
    std::cout << d << std::endl;
    printf("%e\n", d);
    printf("%g\n", d);
}

int main()
{
    double d = 0.0000001;
    print(d);
    d = 1 / 0.5;
    std::cout << std::endl;
    print(d);
}
0.000000
0.000000
1e-07
1.000000e-07
1e-07

2.000000
2.000000
2
2.000000e+00
2

https://godbolt.org/z/PK7MrYqbP

std::to_string() uses %f - lacks precision
std::cout uses %g - lacks the decimal representation if it is exactly an integer not indicating it is a float

@firewave firewave changed the title print float as such in --debug ValueFlow output print (precise) float as such in ValueFlow debug output Feb 1, 2025
@firewave firewave changed the title print (precise) float as such in ValueFlow debug output fixed #13606/13607 - print (precise) float as such in ValueFlow debug output Feb 1, 2025
@firewave firewave force-pushed the vfvalue-float branch 2 times, most recently from 1d3c4fa to 9c3c9af Compare February 1, 2025 19:22
@firewave

This comment was marked as outdated.

@firewave firewave changed the title fixed #13606/13607 - print (precise) float as such in ValueFlow debug output fixed #13606/13607 - consistently print (precise) float as such in ValueFlow debug output Feb 1, 2025
@firewave firewave changed the title fixed #13606/13607 - consistently print (precise) float as such in ValueFlow debug output fixed #13606/#13607 - consistently print (precise) float as such in ValueFlow debug output Feb 1, 2025
@firewave

This comment was marked as resolved.

@firewave firewave force-pushed the vfvalue-float branch 2 times, most recently from ca7d387 to 1ee82af Compare February 6, 2025 01:47
@firewave firewave marked this pull request as ready for review February 6, 2025 01:48
@firewave
Copy link
Collaborator Author

firewave commented Feb 6, 2025

We should probably also add some unit tests testing this.

@firewave firewave force-pushed the vfvalue-float branch 2 times, most recently from 789622e to 4e4997c Compare February 6, 2025 02:15
@firewave firewave merged commit 5ff116d into danmar:main Feb 13, 2025
60 checks passed
@firewave firewave deleted the vfvalue-float branch February 13, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants