Skip to content

rationalize incorrect for Float16 input #49848

Open
@nsajko

Description

@nsajko

Converting the input to Float64 first seems to be a workaround:

julia> setprecision(2^15)
32768

julia> x = Float16(0.000488)
Float16(0.000488)

julia> rx = rationalize(BigInt, x, tol = false)
2047//4196351

julia> Float64(abs(rx - x))
2.3806961713130745e-7

julia> y = Float64(x)
0.00048804283142089844

julia> ry = rationalize(BigInt, y, tol = false)
2047//4194304

julia> Float64(abs(ry - x))
0.0

julia> Float64(abs(ry - y))
0.0

julia> versioninfo()
Julia Version 1.10.0-DEV.1221
Commit 9201414b3d8 (2023-05-05 17:36 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver2)
  Threads: 1 on 8 virtual cores

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorfloat16

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions