-
Notifications
You must be signed in to change notification settings - Fork 39
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
use improved range check of 128 for float64 #157
Conversation
6a92fd6
to
4fa7bfb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall there's a test for the int128
module itself, can you add some testcases for the new function there?
And does this PR change VM behavior at all or just fixing literal construction?
4fa7bfb
to
e7684e7
Compare
I had a giant comment and I think it totally got lost. :( Oh well, it can wait. |
a0dcc29
to
1236372
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of tweaks and this should be good to go:
-
Commit message:
128
->int128
?- Can you mention the new saturating conversion behavior in the message body too?
-
Please add tests for the new float behaviors in
tests/compiler/tint128.nim
.
compiler/int128.nim
Outdated
proc inInt128Range*(arg: float64): bool = | ||
## Simple range check. Of coures NaN is defined not to be in range. | ||
lowerBoundF64 <= arg and arg < upperBoundF64 | ||
|
||
proc toInt128*(arg: float64): Int128 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest adding some docs to describe this function behavior.
proc toInt128*(arg: float64): Int128 = | |
proc toInt128*(arg: float64): Int128 = | |
## Return an `Int128` representing the non-factional part of `arg`. | |
## | |
## Return the maximum or minimum `Int128` when `arg` cannot be represented. |
compiler/int128.nim
Outdated
return Min | ||
if upperBoundF64 <= arg: | ||
return Max | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have picked 0xDEADBEEF or something. But 0 is fine for me as well.
* Add a range check function to test if a float64 is in rage of the int128 type. * Use that range check function for semexpr.checkConvertible * `toInt128(arg: float64)` now has clamping behavior. * fixes nim-works#93 While this fixes the original issue mentioned above, it does not fix or implement the discussions in that issue. They need to be ported to their own issue. converting float64 to int128 is now clamping
1236372
to
1cc5367
Compare
checks have passed. you can take a look again for the merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
bors r+
Build succeeded: |
int128
type.semexpr.checkConvertible
While this fixes the original issue mentioned above, it does not fix or implement the discussions in that issue. They need to be ported to their own issue.