AK: Use correct built-in overload for several math functions#26696
Merged
spholz merged 2 commits intoSerenityOS:masterfrom Apr 5, 2026
Merged
AK: Use correct built-in overload for several math functions#26696spholz merged 2 commits intoSerenityOS:masterfrom
spholz merged 2 commits intoSerenityOS:masterfrom
Conversation
spholz
reviewed
Apr 5, 2026
Member
spholz
left a comment
There was a problem hiding this comment.
LGTM, except for the build failures caused by incorrect function argument names.
No behavior change.
sqrt, sin, cos, tan, atan, atan2, log, log10 used to always call the double built-in. Now the float overload calls the float built-in, the double overload the double built-in, and the long double overload the long double built-in. Ideally, we'd stop calling built-ins for these (see SerenityOS#26662), but as long as we do, we should call the right ones. Similar to the last two commits in SerenityOS#18998.
Contributor
Author
Whoops, sorry about that! ceil / floor don't use that codepath on aarch64, which is where I am 😅 |
spholz
approved these changes
Apr 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sqrt, sin, cos, tan, atan, atan2, log, log10 used to always call the
double built-in.
Now the float overload calls the float built-in, the double overload the
double built-in, and the long double overload the long double built-in.
Ideally, we'd stop calling built-ins for these (see #26662),
but as long as we do, we should call the right ones.
Similar to the last two commits in #18998.
I noticed this because I was trying to check how often our sin() is exact [1], and I forgot to apply something like #26662, meaning I was comparing to system libm (since I was doing this on macOS). And to my surprise, more numbers were exact than if I tested system libm directly [2]. Turns out that was because AK was calling system libm double sin() versions for floats. (Vaguely interesting that
sin()is more often precise for float inputs/outputs than sinf().)1:
AK sin precision count
2:
system libm sin precision count