julia
julia copied to clipboard
Output problem of BigFloat
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
what os? and how did you install Julia?
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)
what os? and how did you install Julia?
CentOS. We just download the binary version.
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 ofprecision(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)
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")
?
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 ofstring(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"