JuliaDynamics/DrWatson.jl

Inconsistent rounding for parameters in savename

Open

#350 opened on 2022年6月27日

GitHub で見る
 (3 comments) (1 reaction) (0 assignees)Julia (915 stars) (94 forks)batch import
buggood first issue

説明

When using savename, some unexpected behaviour can happen when using some parameter values with the sigdigits keyword. This seems to be due to the fact that savename uses the round function to format numbers, which is designed for outputting numbers as strings. One issue occurs when using very small or large numbers, and is due to a known bug in round, but is machine specific.

For example,

julia> savename("test", (p1=3.6e-23,), sigdigits=1)
"test_p1=4.0000000000000004e-23"

but for one order of magnitude larger

julia> savename("test", (p1=3.6e-22,), sigdigits=1)
"test_p1=4e-22"

Additionally, while it may round the correct number of significant digits, the output will not necessarily represent the specified number of significant digits. Specifically, this occurs when there should be additional zeros, which are either not be added to the given number, or are dropped when the number rounds to something that can be represented with fewer digits. For example,

julia> savename("test", (p1=3.5e-6,), sigdigits=4)
"test_p1=3.5e-6"
julia> savename("test", (p1=3.4999e-6,), sigdigits=4)
"test_p1=3.5e-6"

It would probably be more robust to use string formatting methods, for example the Printf.@sprintf macro, to produce the final string after using the round function.

I am using DrWatson v2.9.1 and julia version 1.7.3.

コントリビューターガイド