Skip to content

hashes/hash casts 64-bit floats to 32-bit ints on 32-bit architecture #24769

@pwste-dawid-k

Description

@pwste-dawid-k

Nim Version

2.2.2

Description

The hash proc for floats casts float to int even if these types are not of the same size.

Current Output


Expected Output

Valid hash or error

Known Workarounds

Custom hash proc:

proc hash*(x: float): Hash {.inline.} =
  let y = x + 0.0
  when nimvm:
    # workaround a JS VM bug: bug #16547
    result = hashWangYi1(cast[int64](float64(y)))
  else:
    when not defined(js):
      when sizeof(system.int) == 4:
        result = hashWangYi1(cast[int64](float64(y)))
      else:
        result = hashWangYi1(cast[Hash](y))
    else:
      result = hashWangYiJS(toBits(y))

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions