julia icon indicating copy to clipboard operation
julia copied to clipboard

Output problem of BigFloat

Open zhaoli-IHEP opened this issue 2 years ago • 6 comments

We just found a very strange behavior for BigFloat. The BigFloat(2.1) always shows 2.0 as result. However, when we tried BigFloat(2.1)-BigFloat(2.0), we can see BigFloat(2.1) actually has been converted into 2.1, but it seems the output is not correctly shown. What could be the possible problem?

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.3 (2022-05-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> BigFloat(2.1)-BigFloat(2.0)
0.1

julia> BigFloat(2.1)
2.0

julia> BigFloat(2.0)
2.0

julia> big"2.1"
2.0

zhaoli-IHEP avatar Jul 31 '22 08:07 zhaoli-IHEP

what os? and how did you install Julia?

oscardssmith avatar Jul 31 '22 12:07 oscardssmith

Why does your BigFloat print so few significant digits? What is the output of precision(BigFloat) in julia.

julia> precision(BigFloat)
256

julia> BigFloat(2.1)-BigFloat(2.0)
0.100000000000000088817841970012523233890533447265625

julia> BigFloat(2.1)
2.100000000000000088817841970012523233890533447265625

julia> BigFloat(2.0)
2.0

julia> big"2.1"
2.099999999999999999999999999999999999999999999999999999999999999999999999999986

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

inkydragon avatar Jul 31 '22 13:07 inkydragon

what os? and how did you install Julia?

CentOS. We just download the binary version.

zhaoli-IHEP avatar Aug 02 '22 16:08 zhaoli-IHEP

This is really confusing.


julia> BigFloat(2.1)
2.0

julia> precision(BigFloat)
256

Why does your BigFloat print so few significant digits? What is the output of precision(BigFloat) in julia.

julia> precision(BigFloat)
256

julia> BigFloat(2.1)-BigFloat(2.0)
0.100000000000000088817841970012523233890533447265625

julia> BigFloat(2.1)
2.100000000000000088817841970012523233890533447265625

julia> BigFloat(2.0)
2.0

julia> big"2.1"
2.099999999999999999999999999999999999999999999999999999999999999999999999999986

julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

zhaoli-IHEP avatar Aug 02 '22 16:08 zhaoli-IHEP

Do you get this result when not loading the startup.jl file? (i.e. by launching julia with julia --startup-file=no) ? What is the result of string(big"2.1") ?

rfourquet avatar Sep 14 '22 12:09 rfourquet

Do you get this result when not loading the startup.jl file? (i.e. by launching julia with julia --startup-file=no) ? What is the result of string(big"2.1") ?

Without startup.jl, it still has the same behavior.

[ ~ @XEON9 ]:zhaoli9$ julia --startup-file=no
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org/
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.3 (2022-05-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> precision(BigFloat)
256

julia> BigFloat(2.1)-BigFloat(2.0)
0.1

julia> BigFloat(2.1)
2.0

julia> string(big"2.1")
"2.0"

zhaoli-IHEP avatar Sep 15 '22 01:09 zhaoli-IHEP