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

strconv.parse_f64_prefix() returns incorrect values for negative numbers #4397

Open
divanburger opened this issue Oct 20, 2024 · 0 comments
Open

Comments

@divanburger
Copy link
Contributor

Context

  • Operating System & Odin Version:
    Odin: dev-2024-10:9f609dd74
    OS: openSUSE Tumbleweed, Linux 6.11.0-1-default
    CPU: AMD Ryzen 9 5900X 12-Core Processor
    RAM: 31989 MiB
    Backend: LLVM 18.1.8

Expected Behavior

When running the following Odin program, using odin run .:

package strconv_test

import "core:strconv"
import "core:fmt"

test :: proc(str: string) {
  val, num, ok := strconv.parse_f64_prefix(str)
  fmt.println(str)
  fmt.println("->", val, num, ok)
}

main :: proc() {
  test("80")
  test("160")
  test("-80")
  test("-160")
}

I expect the output to be:

80
-> 80 2 true
160
-> 160 3 true
-80
-> -80 3 true
-160
-> -160 4 true

Current Behavior

Instead I get:

80
-> 80 2 true
160
-> 160 3 true
-80
-> -79.86500349943526 3 true
-160
-> -159.73000699887052 4 true

I understand floating point numbers are not 100% accurate but for negative numbers that seems to be very wrong

@divanburger divanburger changed the title strconv returns incorrect values for negative numbers strconv.parse_f64_prefix() returns incorrect values for negative numbers Oct 20, 2024
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

No branches or pull requests

1 participant