RTL: fix an issue with abs()#1835
Merged
Smit-create merged 1 commit intolcompilers:mainfrom May 18, 2023
Merged
Conversation
Previously the abs() was somehow returning a negative number, because we called it with an int8_t argument, but it was expecting "int" argument. The other bug was that "num" in the for loop stayed at -1 forever. We fixed that by using the condition "num > 0". We also switched to a while loop which make it more readable.
Smit-create
approved these changes
May 18, 2023
Collaborator
Smit-create
left a comment
There was a problem hiding this comment.
Thanks, It's clean!
Collaborator
|
Team, does this actually fix #1825? On latest main, compiling using the following commands ./build0.sh
cmake -DWITH_FMT=yes -DCMAKE_CXX_FLAGS_RELEASE="-Wall -Wextra -O3 -funroll-loops -DNDEBUG" -DWITH_LLVM=yes .
cmake --build . -j16I am experiencing the following: $ python integration_tests/test_bit_length.py
7
3
7
7
$ lpython integration_tests/test_bit_length.py
AssertionError |
Collaborator
|
In #1835 (comment), am I using the correct/expected flags for release mode compilation? Also, $ cat integration_tests/test_bit_length.py
from math import floor, log2
from lpython import i8, i32, i16
def ff3():
x: i16
one: i16
one = i16(1)
x = -i16(one << i16(13))
print("ff3(): x.bit_length() =", x.bit_length(), ", where x is", x)
assert i32(x.bit_length()) == 14
ff3()
$ python integration_tests/test_bit_length.py
ff3(): x.bit_length() = 14 , where x is -8192
$ lpython integration_tests/test_bit_length.py
ff3(): x.bit_length() = 0 , where x is -8192
AssertionError |
Contributor
Author
|
@Shaikh-Ubaid can you open up a new issue? It looks like you are getting a failure: But it works on my laptop as well as the CI. Let's try to reproduce the problem that you are seeing and then we'll fix it. |
Collaborator
Sure. Opened here #1836. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously the abs() was somehow returning a negative number, because we called it with an int8_t argument, but it was expecting "int" argument.
The other bug was that "num" in the for loop stayed at -1 forever. We fixed that by using the condition "num > 0". We also switched to a while loop which make it more readable.
Fixes #1825.