Skip to content

Float to int conversion loses sign #20102

@rotu

Description

@rotu

Converting a large positive floating point number to an integer can result in a large negative integer.

Example

let l = int.high
echo l
echo l.float.int

https://play.nim-lang.org/#ix=45QL

Current Output

please check whether the problem still exists in git head before posting,
see rebuilding the compiler.

9223372036854775807
-9223372036854775808

Expected Output

something like

9223372036854775807
9223372036854775807

or

9223372036854775807
9223372036854774784

Additional Information

nim --version
Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

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