GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Possible shortcut for format_exact_opt in Grisu3 · Issue #110129 · rust-lang/rust

Possible shortcut for format_exact_opt in Grisu3 #110129

New issue
Copy link
New issue
Copy link
Closed
#110389
Closed
Possible shortcut for format_exact_opt in Grisu3#110129
#110389
Copy link
Labels
A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.

Description

@mazong1123
mazong1123
opened on Apr 10, 2023
Issue body actions

In the .NET implementation of Grisu3, there's a shortcut to jump out earlier when the fractionals or integrals cannot meet the determination of requested digits. This significantly improved the performance of converting floating number to string as it falls back even without starting trying the Grisu3 algorithm. This was originally added in this PR, and shipped along with all later .NET versions so it's proved working.

Below is the code snippet from current .NET repo:

                // We deviate from the original algorithm here and do some early checks to determine if we can satisfy requestedDigits.
                // If we determine that we can't, we exit early and avoid most of the heavy lifting that the algorithm otherwise does.
                //
                // When fractionals is zero, we can easily determine if integrals can satisfy requested digits:
                //      If requestedDigits >= 11, integrals is not able to exhaust the count by itself since 10^(11 -1) > uint.MaxValue >= integrals.
                //      If integrals < 10^(requestedDigits - 1), integrals cannot exhaust the count.
                //      Otherwise, integrals might be able to exhaust the count and we need to execute the rest of the code.
                if ((fractionals == 0) && ((requestedDigits >= 11) || (integrals < SmallPowersOfTen[requestedDigits - 1])))
                {
                    Debug.Assert(buffer[0] == '\0');
                    length = 0;
                    kappa = 0;
                    return false;
                }

I'm wondering do we consider apply the same shortcut just after vint and vfrac extracted at line 489 of grisu.rs?

Activity

  1. jyn514
    added
    I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
    T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
    A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmetic
    on Apr 10, 2023
  2. mazong1123 commented on Apr 10, 2023

    @mazong1123
    mazong1123
    on Apr 10, 2023
    ContributorAuthor
    More actions

    I'm going to prepare a PR later this week if no objection.

  3. bors
    added a commit that references this issue on Apr 25, 2023

    Auto merge of rust-lang#110389 - mazong1123:add-shortcut-for-grisu3, …

    This issue will close once commit 91b61a4 is merged into the 'master' branch.
    91b61a4
  4. bors
    closed this as completedin b0a85d6on Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-floating-pointArea: Floating point numbers and arithmeticArea: Floating point numbers and arithmeticC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.