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

Add float.to-fixed and float.to-precision #7831

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

crai0
Copy link
Contributor

@crai0 crai0 commented Mar 9, 2025

Add two new float to string conversion methods that mimic JavaScript's Number.toFixed() and Number.toPrecision().

They are implemented as no_mangle functions similar to the already existing float to shared string conversion.

Closes #5822

crai0 added 3 commits March 9, 2025 23:09
Add two new float to string conversion methods that mimic
JavaScript's Number.toFixed() and Number.toPrecision().

They are implemented as no_mangle functions similar to the already
existing float to shared string conversion.

Closes slint-ui#5822
@crai0 crai0 force-pushed the float_to_string_conversion branch from 9e9af47 to 8cda0ad Compare March 9, 2025 22:59
@crai0 crai0 force-pushed the float_to_string_conversion branch from 8cda0ad to 3605c89 Compare March 9, 2025 23:09
@crai0
Copy link
Contributor Author

crai0 commented Mar 10, 2025

I noticed that the mcu_esp tests are not building because f64::abs isn't available in core in version 1.82.0 which the Xtensa toolchain is using. It is part of core since version 1.85.0 though. Is this a reason to raise MSRV or should I rather implement it by setting the sign bit using from_bits/to_bits?

I haven't looked into why the cpp_test_driver fails with a mismatch in two cases yet but I guess it has to do something with floating point precision.

@ogoffart
Copy link
Member

Thanks for the PR. I'll review later because I'm busy this week.
But the float issue on embedded is because some functions don't exist on that platform. But we can fix it by adding a use num_traits::Float; like we do in a few places already.

Sign up for free to 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.

Float-to-string conversion while controlling decimal place count
2 participants