JuliaMath / JuliaMath/FixedPointNumbers.jl

Wrong printing of `Fixed` numbers

Aperta
#307 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Julia
Stelle
95
Fork
38
Merge medio
13m
PR unite (30g)
2

Descrizione

Either I have totally misunderstood the documentation or printing of `Fixed` numbers is wrong.

```
julia> Fixed{Int8,2}(0.25)
0.2Q5f2

julia> Fixed{Int8,3}(0.125)
0.12Q4f3
```

Looking into `FixedPointNumbers.jl/show` leads to
```
digits=ceil(Int, f * log10_2)
```
which is wrong, as for `2^-f` the number of decimal fraction digits scales linearly and not logarithmic with `f`'s number of binary fraction digits, as you can see here
```
julia> 2.0.^(-1:-1:-10)
10-element Vector{Float64}:
0.5
0.25
0.125
0.0625
0.03125
0.015625
0.0078125
0.00390625
0.001953125
0.0009765625
```

Consequently this can be fixed by using `digits=f`.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Read the FixedPointNumbers.jl/show implementation, focusing on how the decimal digit count is calculated for fixed-point values. Reproduce the two examples from the issue and verify that the output uses enough fractional digits to represent Fixed{Int8,2}(0.25) and Fixed{Int8,3}(0.125) correctly.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
julia
Ambito
tooling
Tipo di issue
Bug
Difficoltà
1/5
Tempo stimato
Meno di un'ora
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.