Skip to content

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

Merged
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:vfvalue-float
Feb 13, 2025
Merged

fixed #13606/#13607 - consistently print (precise) float as such in ValueFlow debug output#7274
firewave merged 3 commits into
cppcheck-opensource:mainfrom
firewave:vfvalue-float

Conversation

@firewave

Copy link
Copy Markdown
Collaborator

No description provided.

@firewave

Copy link
Copy Markdown
CollaboratorAuthor

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

#include<iostream>
#include<string>voidprint(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);
}
intmain()
{
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

@firewavefirewave changed the title print float as such in --debug ValueFlow outputprint (precise) float as such in ValueFlow debug outputFeb 1, 2025
@firewavefirewave changed the title print (precise) float as such in ValueFlow debug outputfixed #13606/13607 - print (precise) float as such in ValueFlow debug outputFeb 1, 2025
@firewave
firewaveforce-pushed the vfvalue-float branch 2 times, most recently from 1d3c4fa to 9c3c9afCompareFebruary 1, 2025 19:22
@firewave

This comment was marked as outdated.

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

This comment was marked as resolved.

@firewave
firewaveforce-pushed the vfvalue-float branch 2 times, most recently from ca7d387 to 1ee82afCompareFebruary 6, 2025 01:47
@firewave
firewave marked this pull request as ready for review February 6, 2025 01:48
@firewave

Copy link
Copy Markdown
CollaboratorAuthor

We should probably also add some unit tests testing this.

@firewave
firewaveforce-pushed the vfvalue-float branch 2 times, most recently from 789622e to 4e4997cCompareFebruary 6, 2025 02:15
@firewave
firewave merged commit 5ff116d into cppcheck-opensource:mainFeb 13, 2025
@firewave
firewave deleted the vfvalue-float branch February 13, 2025 16:53
Sign up for freeto 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

@firewave@danmar