Skip to content

str_to_float converts fractional values in reverse #1015

Closed
@jdm

Description

@jdm
Contributor

The routine uses vec::pop_char instead of vec::shift_char.

Activity

Yoric

Yoric commented on Oct 11, 2011

@Yoric
Contributor

Ok, I'll pick this issue as my first foray into rust.

Yoric

Yoric commented on Oct 11, 2011

@Yoric
Contributor

Actually, it's a bit worse: str_to_float "1.5" returns 1.

jdm

jdm commented on Oct 11, 2011

@jdm
ContributorAuthor

Oh right, I remember coming across that before.

    let i = 1u;
    while (i < len) {
        total += dec_val(str::shift_char(right)) as float /
                 (int::pow(10, i) as float);
        i += 1u;
    }

Either start the loop at 0u and use i+1u in pow, or just make the loop

i <= len
. I think that should resolve it.

Yoric

Yoric commented on Oct 12, 2011

@Yoric
Contributor

Well, eventually, I rewrote the whole function. This int::pow was also a problem as each call is linear.

added a commit that references this issue on May 21, 2022

Auto merge of rust-lang#8802 - smoelius:allow-expect-unwrap-in-tests,…

added a commit that references this issue on Aug 5, 2023
added a commit that references this issue on Jun 4, 2024
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

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Yoric@jdm

        Issue actions

          str_to_float converts fractional values in reverse · Issue #1015 · rust-lang/rust