Skip to content

setrounding seems to do nothing on Windows 10 when parsing Float64 #26934

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

Closed
Kolaru opened this issue Apr 30, 2018 · 3 comments
Closed

setrounding seems to do nothing on Windows 10 when parsing Float64 #26934

Kolaru opened this issue Apr 30, 2018 · 3 comments
Labels
system:windows Affects only Windows

Comments

@Kolaru
Copy link

Kolaru commented Apr 30, 2018

Consider the following

xup = setrounding(Float64, RoundUp) do
    parse(Float64, "0.1")
end

xdown = setrounding(Float64, RoundDown) do
    parse(Float64, "0.1")
end

On my Windows machine it yields xdown == xup, which is unexpected as 0.1 can not be represented exactly in binary form.

More generally it seems like whatever was told to setrounding, parse does the same rounding, as indicates the following (dirty) test:

c = 0
for i in 1:100
    s = reduce(*, "0.", string.(rand(0:9, 50)))
    xnearest = parse(Float64, s)
    xup = setrounding(Float64, RoundUp) do
        parse(Float64, s)
    end
    xdown = setrounding(T, RoundDown) do
        parse(Float64, s)
    end
    if xup == xnearest == xdown
        c += 1
    end
end

On Windows it yields c == 100 (the result of the parsing is always the same) while on Linux it yields the expected c == 0.

The Linux results were obtained using JuliaBox (for convenience) and the versioninfo() on my Windows machine is the following:

Julia Version 0.6.2
Commit d386e40c17* (2017-12-13 18:08 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
@dpsanders
Copy link
Contributor

cc @simonbyrne

@dpsanders
Copy link
Contributor

Seems weird that the behaviour is different on Linux and Windows.

Is it just coincidence that jl_try_substrtod works with the rounding mode set?
(And by the way, is there any particular reason that jl_try_substrtod is written in C instead of Julia?)

@JeffBezanson JeffBezanson added the system:windows Affects only Windows label May 3, 2018
@simonbyrne
Copy link
Contributor

setrounding has now been deprecated: #27166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:windows Affects only Windows
Projects
None yet
Development

No branches or pull requests

4 participants