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 ecvt/fcvt issues w.r.t. value==0 and ndigit==0 #1282

Merged

Conversation

GabrielRavier
Copy link
Collaborator

Before this commit, cosmopolitan had some issues with handling arguments
of 0 and signs, such as returning an incorrect sign when the input value
== -0.0, and incorrectly handling ndigit == 0 on fcvt (ndigit determines
the amount of digits after the radix character on fcvt, thus the parts
before it still must be outputted before fcvt's job is completely done).

This patch fixes these issues, and adds tests with corresponding inputs.

Before this commit, cosmopolitan had some issues with handling arguments
of 0 and signs, such as returning an incorrect sign when the input value
== -0.0, and incorrectly handling ndigit == 0 on fcvt (ndigit determines
the amount of digits *after* the radix character on fcvt, thus the parts
before it still must be outputted before fcvt's job is completely done).

This patch fixes these issues, and adds tests with corresponding inputs.
@github-actions github-actions bot added the libc label Sep 7, 2024
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.

These functions aren't part of the C standard anymore. I agree it's worth it to have them be more correct and consistent with glibc. What you discovered is also a bug in OpenbSD. I recommend sending them a patch, so they'll know Cosmo is helping them. It's also a bug in Apple Libc. OTOH FreeBSD has removed these APIs.

@jart jart merged commit f882887 into jart:master Sep 8, 2024
6 checks passed
@GabrielRavier
Copy link
Collaborator Author

GabrielRavier commented Sep 8, 2024

w.r.t. glibc consistency I was actually only really trying to make changes that I could back up with a reasonable interpretation of POSIX-2004 (i.e. discarding cases that are either deliberately implementation defined (e.g. *decpt can be 0 or 1 when value == 0) or UB (e.g. ndigit < 0 seems to be UB)) but if you think it'd be better to try to make it behave exactly like glibc I could also do that (well, technically, exactly like glibc would be going clearly too far though, given glibc's implementation is actually buggy in some respects: https://sourceware.org/bugzilla/show_bug.cgi?id=29556, but ofc a few things could still be realistically be done to make it really close)

@GabrielRavier
Copy link
Collaborator Author

GabrielRavier commented Sep 8, 2024

I'll also try to make a bug report to OpenBSD (though that'll take a bit given I'll want to setup an OpenBSD VM to do it properly) but do you know how to report bugs to Apple for libc at all ? (if there's even a way to do that, especially given I don't have any Apple computer in the first place...)

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