Skip to content

Fix #76093: Format strings w/o loss of precision w/ FORMAT_TYPE_DECIMAL #9909

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

Closed
wants to merge 2 commits into from

Conversation

lucaswerkmeister
Copy link

Resubmit of @cscott’s PR #7782. Rebased onto latest master (pretty sure the ship to make this target PHP 8.2 has sailed), resolving in particular a conflict with 163a278.

Applied @cmb69’s suggestion to check sizeof at compile time. Did not apply @cmb69’s suggestion to revert to zend_parse_method_parameters(); if I understand correctly, the suggested replacement for EMPTY_SWITCH_DEFAULT_CASE() would only evaluate if type == FORMAT_TYPE_DEFAULT, so with a non-default $type, an invalid value wouldn’t have its type checked.

Passing the argument to NumberFormat::format() as a number loses
precision if the value can not be represented precisely as a
double or long integer.  The icu library provides a "decimal number"
type that avoids the loss of prevision when the value is passed
as a string.  Add a new FORMAT_TYPE_DECIMAL to explicitly request
the argument be converted to a string and then passed to icu
that way.
This extends the argument types of NumberFormat::formatCurrency() to
include string, in the same way the earlier patch extended
NumberFormat::format() to allow a string.  This allows formatting
values which can't be represented precisely as a double or long
integer, using the "decimal number" type of the icu library.
@lucaswerkmeister
Copy link
Author

If we wanted to keep using zend_parse_method_parameters(), I suppose we could pick an ASCII letter (N still seems to be free) and add that to zend_parse_arg_impl() as the specifier for zend_parse_arg_str_or_number()?

@dstogov
Copy link
Member

dstogov commented Oct 9, 2023

It looks like this PR is outdated. We might miss it. Sorry.
I'm closing it now.
If you still like to merge it, please update it and re-open.

@dstogov dstogov closed this Oct 9, 2023
@lucaswerkmeister
Copy link
Author

Rebased and pushed to the same branch. I don’t have permission to reopen this PR, it seems – would you like me to open a new one?

Also, I have no idea what GitHub did there, I certainly didn’t do anything related to this PR three days ago…
image

@bukka
Copy link
Member

bukka commented Oct 13, 2023

@lucaswerkmeister It was done automatically (probably by GitHub). Seems like all code owners got assigned the open PR's touching their code.

It seems like I can't also re-open it (even though I should have all perms to do that) as it was force pushed when closed. Best if you could open a new PR.

@lucaswerkmeister
Copy link
Author

Alright, done at #12432.

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

Successfully merging this pull request may close these issues.

4 participants