Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid uint64 literal says -72057594037927936 can't be converted to uint64. #14522

Closed
treeform opened this issue May 31, 2020 · 5 comments · Fixed by #23930
Closed

Valid uint64 literal says -72057594037927936 can't be converted to uint64. #14522

treeform opened this issue May 31, 2020 · 5 comments · Fixed by #23930
Labels

Comments

@treeform
Copy link
Contributor

echo 0xFF000000_00000000.uint64
Error: -72057594037927936 can't be converted to uint64

https://play.nim-lang.org/#ix=2nY6

I think its treating all hex literals as signed int64, so it can't accept one that has a negative bit set. Some where in some conversions this happens?

My compiler:

Nim Compiler Version 1.2.0 [Windows: amd64]
Compiled at 2020-04-03
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 7e83adff84be5d0c401a213eccb61e321a3fb1ff
active boot switches: -d:release
@treeform
Copy link
Contributor Author

Hmm Recruit_main707, pointed out that cast works

echo cast[uint64](0xFF00000000000000)

Very strange!

@treeform
Copy link
Contributor Author

Hmm leorize, points out that:

echo 0xFF00000000000000u64

Also works!

@timotheecour
Copy link
Member

update as of 3ceaf5c

when true:
  # echo 0xFF000000_00000000.uint64 # Error: -72057594037927936 can't be converted to uint64
  echo 0xFF000000_00000000'u64 # ok
  const a = 0xFF000000_00000000
  # echo a.uint64 # Error: -72057594037927936 can't be converted to uint64
  # var b: uint64 = a # Error: type mismatch:

@ringabout
Copy link
Member

Duplicate of #12700

let x = 0xFF000000_00000000
echo uint64(x)

works

@treeform
Copy link
Contributor Author

Thank you! Great fix.

narimiran pushed a commit that referenced this issue Sep 13, 2024
fixes #14522
fixes #22085
fixes #12700
fixes #23132
closes #22343 (succeeded by this PR)
completes nim-lang/RFCs#175

follow up #12688

(cherry picked from commit f0e1eef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants