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 ConstantFloatType value dump precision #2358

Merged
merged 1 commit into from Sep 29, 2023

Conversation

mvorisek
Copy link
Contributor

When dumping a float value, we need:

  • ensure . is always present in finite values (/wo . the number type is integer)
  • always dump with full precision ((string) float_expr cast is affected by precision php.ini)
  • never dump more digits than needed

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

@mvorisek mvorisek changed the base branch from 1.11.x to 1.10.x April 22, 2023 09:44

return $formatted;
},
fn (): string => $this->castFloatToString($this->value),
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC this is a perf critical path.

I think we need a benchmark to show whether this edge-case fixing leads to a perf regression in the common case

Copy link
Contributor

Choose a reason for hiding this comment

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

Scratch that. I mixed it up with #2080

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#2080 - please see phpstan/phpstan#9228, the comparison should be even simplifid to === only, as any other float value is different

@staabm
Copy link
Contributor

staabm commented Apr 25, 2023

fwiw, I just stumbled over a pretty similar logic in sebastian/exporter:

https://github.com/sebastianbergmann/exporter/blob/997c7034005f045466fcf66d001821153d537c4e/src/Exporter.php#L224-L240

@mvorisek
Copy link
Contributor Author

mvorisek commented Jun 7, 2023

PR is done.

@ondrejmirtes ondrejmirtes merged commit d25b897 into phpstan:1.10.x Sep 29, 2023
376 of 379 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants