about summary refs log tree commit diff
path: root/library/core/src/num/dec2flt
AgeCommit message (Collapse)AuthorLines
2025-08-26remove deprecated Error::description in implsMarijn Schouten-11/+6
2025-08-11Make a James Bond referenceJakub Stasiak-2/+2
2025-08-11dec2flt: Provide more valid inputs examplesJakub Stasiak-0/+2
I was just looking at the specifics of how the parsing is handled here and I wasn't sure if the examples were incomplete or the grammar below was misleading. The grammar was correct so I figured I'd add these examples to clarify.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-3/+3
2025-06-03move `test-float-parse` tool into `src/tools` dironur-ozkan-1/+1
Obviously `test-float-parse` is a tool like any other in `src/tools`. Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-05-18float: Add `f16` parsing and printingTrevor Gross-4/+69
Use the existing Lemire (decimal -> float) and Dragon / Grisu algorithms (float -> decimal) to add support for `f16`. This allows updating the implementation for `Display` to the expected behavior for `Display` (currently it prints the a hex bitwise representation), matching other floats, and adds a `FromStr` implementation. In order to avoid crashes when compiling with Cranelift or on targets where f16 is not well supported, a fallback is used if `cfg(target_has_reliable_f16)` is not true.
2025-03-07Rollup merge of #138034 - thaliaarchi:use-prelude-size-of, r=tgross35Matthias Krüger-1/+0
library: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80. try-job: test-various try-job: x86_64-gnu try-job: x86_64-msvc-1
2025-03-06library: Use size_of from the prelude instead of importedThalia Archibald-1/+0
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-02dec2flt: Refactor the fast pathTrevor Gross-24/+23
This is just a bit of code cleanup to make use of returning early.
2025-03-02dec2flt: Refactor float traitsTrevor Gross-111/+203
A lot of the magic constants can be turned into expressions. This reduces some code duplication. Additionally, add traits to make these operations fully generic. This will make it easier to support `f16` and `f128`.
2025-03-02dec2flt: Rename fields to be consistent with documented notationTrevor Gross-14/+18
2025-03-02dec2flt: Rename `Number` to `Decimal`Trevor Gross-9/+9
The previous commit renamed `Decimal` to `DecimalSeq`. Now, rename the type that represents a decimal floating point number to be `Decimal`. Additionally, add some tests for internal behavior.
2025-03-02dec2flt: Rename `Decimal` to `DecimalSeq`Trevor Gross-22/+39
This module currently contains two decimal types, `Decimal` and `Number`. These names don't provide a whole lot of insight into what exactly they are, and `Number` is actually the one that is more like an expected `Decimal` type. In accordance with this, rename the existing `Decimal` to `DecimalSeq`. This highlights that it contains a sequence of decimal digits, rather than representing a base-10 floating point (decimal) number. Additionally, add some tests to validate internal behavior.
2025-03-02dec2flt: Update documentation of existing methodsTrevor Gross-17/+35
Fix or elaborate existing float parsing documentation. This includes introducing a convention that should make naming more consistent.
2025-01-20core: add `#![warn(unreachable_pub)]`Urgau-18/+19
2024-11-13update outdated comment about test-float-parseonur-ozkan-1/+1
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-4/+4
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-16Rollup merge of #126271 - diondokter:dec2flt-skip-fast-path, r=tgross35Trevor Gross-2/+4
Skip fast path for dec2flt when optimize_for_size Tracking issue: https://github.com/rust-lang/rust/issues/125612 Skip the fast algorithm when optimizing for size. When compiling for https://github.com/quartiq/stabilizer I get these numbers: Before ``` text data bss dec hex filename 192192 8 49424 241624 3afd8 dual-iir ``` After ``` text data bss dec hex filename 191632 8 49424 241064 3ada8 dual-iir ``` This saves 560 bytes.
2024-07-17Cfg nitDion Dokter-1/+1
Co-authored-by: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-06-24Small fixme in core now that split_first has no codegen issuesPavel Grigorenko-6/+2
2024-06-11Skip fast path for dec2flt when optimize_for_sizeDion Dokter-2/+4
2023-08-14explain why we can mutate the FPU control wordRalf Jung-0/+12
2023-04-10Improve the floating point parser in `dec2flt`.Tobias Decking-287/+187
* Remove all remaining traces of unsafe. * Put `parse_8digits` inside a loop. * Rework parsing of inf/NaN values.
2023-03-04Update comment.Tobias Decking-1/+1
2023-03-04typoTobias Decking-1/+1
2023-03-04Add inlining annotationsTobias Decking-1/+18
2023-02-10Remove a couple of `#[doc(hidden)] pub fn` and their `#[feature]` gatesTobias Bucher-10/+7
2023-01-14Fix some missed double spaces.André Vennberg-1/+1
2022-10-14more dupe word typosRageking8-1/+1
2022-09-22Added which number is computed in compute_float.Orson Peters-1/+1
2022-09-11Fix naming format of IEEE 754 standardLingMan-1/+1
Currently the documentation of f64::min refers to "IEEE-754 2008" while the documentation of f64::minimum refers to "IEEE 754-2019". Note that one has the format IEEE,hyphen,number,space,year while the other is IEEE,space,number,hyphen,year. The official IEEE site [1] uses the later format and it is also the one most commonly used throughout the codebase. Update all comments and - more importantly - documentation to consistently use the official format. [1] https://standards.ieee.org/ieee/754/4211/
2022-05-28Corrected EBNF grammar for from_strIsaac Chen-1/+0
Previously, the `Number` part of the EBNF grammar had an option for `'.' Digit*`, which would include the string "." (a single decimal point). This is not valid, and does not return an Ok as stated. The corrected version removes this, and still allows for the `'.' Digit+` case with the already existing `Digit* '.' Digit+` case.
2022-05-23Rollup merge of #96129 - mattheww:2022-04_float_rounding, r=Dylan-DPCDylan DPC-2/+4
Document rounding for floating-point primitive operations and string parsing The docs for floating point don't have much to say at present about either the precision of their results or rounding behaviour. As I understand it[^1][^2], Rust doesn't support operating with non-default rounding directions, so we need only describe roundTiesToEven. [^1]: https://github.com/rust-lang/rust/issues/41753#issuecomment-299322887 [^2]: https://github.com/llvm/llvm-project/issues/8472#issuecomment-980888781 This PR makes a start by documenting that for primitive operations and `from_str()`.
2022-05-15Rename `eq_ignore_case` to `starts_with_ignore_case`gabriel-doriath-dohler-4/+4
The method doesn't test for equality. It tests if the object starts with a given byte array, so its name is confusing.
2022-04-16Document the numeric value returned by string parsing for floatsMatthew Woodcraft-2/+4
2022-03-10make float parsing docs more comprehensiveAnton Lazarev-5/+8
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2021-12-15Rollup merge of #91916 - steffahn:fix-typos, r=dtolnayMatthias Krüger-1/+1
Fix a bunch of typos I hope that none of these files is not supposed to be modified. FYI, I opened separate PRs for typos in submodules, in the respective repositories * https://github.com/rust-lang/stdarch/pull/1267 * https://github.com/rust-lang/backtrace-rs/pull/455
2021-12-14Fix a bunch of typosFrank Steffahn-1/+1
2021-12-12Stabilize asm! and global_asm!Amanieu d'Antras-0/+1
They are also removed from the prelude as per the decision in https://github.com/rust-lang/rust/issues/87228. stdarch and compiler-builtins are updated to work with the new, stable asm! and global_asm! macros.
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-7/+2
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-07-17Changed dec2flt to use the Eisel-Lemire algorithm.Alex Huszagh-2395/+2145
Implementation is based off fast-float-rust, with a few notable changes. - Some unsafe methods have been removed. - Safe methods with inherently unsafe functionality have been removed. - All unsafe functionality is documented and provably safe. - Extensive documentation has been added for simpler maintenance. - Inline annotations on internal routines has been removed. - Fixed Python errors in src/etc/test-float-parse/runtests.py. - Updated test-float-parse to be a library, to avoid missing rand dependency. - Added regression tests for #31109 and #31407 in core tests. - Added regression tests for #31109 and #31407 in ui tests. - Use the existing slice primitive to simplify shared dec2flt methods - Remove Miri ignores from dec2flt, due to faster parsing times. - resolves #85198 - resolves #85214 - resolves #85234 - fixes #31407 - fixes #31109 - fixes #53015 - resolves #68396 - closes https://github.com/aldanor/fast-float-rust/issues/15
2021-06-23Use HTTPS links where possibleSmitty-1/+1
2021-03-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-5/+7
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-22Add ability to read NaN/InfinityJubilee Young-5/+7
2021-03-22Fix asm! from AT&T to Intel syntaxJosh Stone-2/+2