`Fixed` does not fully support `fraction bits >= storage bits - 1`
还没有人认领这个 Issue。
评估
调研方向
首先使用 Fixed{Int8, 6}(1)、Fixed{Int8, 7}(1)、sprint(show, ...),以及 Unitful 乘法示例运行 REPL 复现。比较 f=6 和 f=7 的显示路径;完成的标准是 f>=b-1 的值显示时没有额外的引号,并且 Unitful 表达式不再引发所示的 MethodError。
由索引模型根据 Issue 内容生成。
描述
Somehow related to #311 as it also concerns the lack of generalization, but in the other direction. If precision is really important, but range is not, we want to use all the bits to represent small numbers accepting that larger numbers, like 1, can no longer be represented.
Let b be the number of bits of the storage type and f the number of bits of the fraction. For f < b - 1 everything is fine:
using FixedPointNumbers, Unitful
julia> Fixed{Int8, 6}(1)
1.0Q1f6
julia> Fixed{Int8, 6}(1)u"m"
1.0Q1f6 m
However, for f >= b - 1 things start to break down when using units:
julia> Fixed{Int8, 7}(1)
"0.992188"
julia> Fixed{Int8, 7}(1)u"m"
ERROR: MethodError: no method matching *(::String, ::Unitful.FreeUnits{(m,), 𝐋, nothing})
The function `*` exists, but no method is defined for this combination of argument types.
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:642
*(::Missing, ::Unitful.Units)
@ Unitful ~/.julia/packages/Unitful/8Qjvg/src/units.jl:94
*(::LinRange, ::Unitful.Units)
@ Unitful ~/.julia/packages/Unitful/8Qjvg/src/range.jl:143
...
Stacktrace:
[1] top-level scope
@ REPL[86]:1
The reason seems to be the additional quotes which are printed for f = 7 instead of f = 6, as can be seen above or more clearly below
julia> sprint(show, Fixed{Int8, 6}(1))
"1.0Q1f6"
julia> sprint(show, Fixed{Int8, 7}(1))
"\"0.992188\""
- 主要语言
- Julia
- 星标
- 95
- 派生
- 38
- 平均合并
- 1 天 7 分钟
- 30 天内合并 PR
- 4
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaMath/FixedPointNumbers.jl 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
JuliaMath/FixedPointNumbers.jl#310 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 5/5 一周以上 新手友好度 42/100
JuliaMath/FixedPointNumbers.jl#331 · 4 条评论 ·
-
add-on enhancement
难度 5/5 一周以上 新手友好度 35/100
JuliaMath/FixedPointNumbers.jl#311 · 4 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
查看 JuliaMath/FixedPointNumbers.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bot-test documentation
难度 2/5 半天 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 70/100
JuliaComputing/jh#63 · 1 条评论 ·