-
Notifications
You must be signed in to change notification settings - Fork 170
Implement round
built-in function
#199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c5ea37
Write the test for `round` built-in function
namannimmo10 4c26959
Implement runtime `round` function
namannimmo10 0db45eb
Implement compile time `round` function
namannimmo10 e59dc65
Update tests
namannimmo10 86cf3c7
Add more tests
namannimmo10 f830649
Merge branch 'main' into round
namannimmo10 6b2ca3b
Handle special case for `round`
namannimmo10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from ltypes import f64 | ||
|
||
def test_round(): | ||
f: f64 | ||
f = 5.678 | ||
print(round(f)) | ||
f = -183745.23 | ||
print(round(f)) | ||
f = 44.34 | ||
print(round(f)) | ||
f = 0.5 | ||
print(round(f)) | ||
f = -50.5 | ||
print(round(f)) | ||
f = 1.5 | ||
print(round(f)) | ||
assert round(13.001) == 13 | ||
assert round(-40.49999) == -40 | ||
assert round(0.5) == 0 | ||
assert round(-0.5) == 0 | ||
assert round(1.5) == 2 | ||
assert round(50.5) == 50 | ||
assert round(56.78) == 57 | ||
|
||
|
||
test_round() |
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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 17 {}) main_program [] []), test_namedexpr: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 4 ord lpython_builtin [] ord Private), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Integer 4 []) Source Public Required .false.)}) test_namedexpr [] [(= (Var 2 x) (NamedExpr (Var 2 y) (ConstantInteger 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (FunctionCall 2 ord () [(ConstantString "3" (Character 1 1 () []))] [] (Integer 4 []) (ConstantInteger 51 (Integer 4 [])) ()) (Integer 4 [])) [(= (Var 2 x) (ConstantInteger 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (ConstantInteger 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (ConstantInteger 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) | ||
(TranslationUnit (SymbolTable 1 {lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 18 {}) main_program [] []), test_namedexpr: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 4 ord lpython_builtin [] ord Private), x: (Variable 2 x Local () () Default (Integer 4 []) Source Public Required .false.), y: (Variable 2 y Local () () Default (Integer 4 []) Source Public Required .false.)}) test_namedexpr [] [(= (Var 2 x) (NamedExpr (Var 2 y) (ConstantInteger 0 (Integer 4 [])) (Integer 4 [])) ()) (If (NamedExpr (Var 2 a) (FunctionCall 2 ord () [(ConstantString "3" (Character 1 1 () []))] [] (Integer 4 []) (ConstantInteger 51 (Integer 4 [])) ()) (Integer 4 [])) [(= (Var 2 x) (ConstantInteger 1 (Integer 4 [])) ())] []) (WhileLoop (NamedExpr (Var 2 a) (ConstantInteger 1 (Integer 4 [])) (Integer 4 [])) [(= (Var 2 y) (ConstantInteger 1 (Integer 4 [])) ())])] Source Public Implementation () .false. .false.)}) []) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 20 {}) _lfortran_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 19 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 2 pow () [(ConstantInteger 2 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) (ConstantInteger 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 3 pow () [(Var 3 a) (Var 3 b)] [] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) []) | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 21 {}) _lfortran_main_program [] [(SubroutineCall 1 main0 () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main0: (Subroutine (SymbolTable 4 {c: (Variable 4 c Local () () Default (Integer 4 []) Source Public Required .false.)}) main0 [] [(SubroutineCall 1 test_pow () [] ()) (= (Var 4 c) (FunctionCall 1 test_pow_1 () [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) () ()) ())] Source Public Implementation () .false. .false.), main_program: (Program (SymbolTable 20 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_pow: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 2 pow 6 pow lpython_builtin [] pow Private)}) test_pow [] [(= (Var 2 a) (FunctionCall 2 pow () [(ConstantInteger 2 (Integer 4 [])) (ConstantInteger 2 (Integer 4 []))] [] (Integer 4 []) (ConstantInteger 4 (Integer 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_pow_1: (Function (SymbolTable 3 {_lpython_return_variable: (Variable 3 _lpython_return_variable ReturnVar () () Default (Integer 4 []) Source Public Required .false.), a: (Variable 3 a In () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 3 b In () () Default (Integer 4 []) Source Public Required .false.), pow: (ExternalSymbol 3 pow 6 pow lpython_builtin [] pow Private), res: (Variable 3 res Local () () Default (Integer 4 []) Source Public Required .false.)}) test_pow_1 [(Var 3 a) (Var 3 b)] [(= (Var 3 res) (FunctionCall 3 pow () [(Var 3 a) (Var 3 b)] [] (Integer 4 []) () ()) ()) (= (Var 3 _lpython_return_variable) (Var 3 res) ()) (Return)] (Var 3 _lpython_return_variable) Source Public Implementation ())}) []) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 19 {}) _lfortran_main_program [] [(SubroutineCall 1 test_ord () [] ()) (SubroutineCall 1 test_chr () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 18 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_chr: (Subroutine (SymbolTable 3 {chr: (ExternalSymbol 3 chr 5 chr lpython_builtin [] chr Private), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_chr [] [(= (Var 3 i) (ConstantInteger 48 (Integer 4 [])) ()) (= (Var 3 s) (FunctionCall 3 chr () [(Var 3 i)] [] (Character 1 -2 () []) () ()) ()) (Assert (Compare (Var 3 s) Eq (ConstantString "0" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [(ConstantInteger 48 (Integer 4 []))] [] (Character 1 -2 () []) (ConstantString "0" (Character 1 1 () [])) ()) Eq (ConstantString "0" (Character 1 1 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_ord: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 5 ord lpython_builtin [] ord Private), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord [] [(= (Var 2 s) (ConstantString "1" (Character 1 1 () [])) ()) (= (Var 2 i) (FunctionCall 2 ord () [(Var 2 s)] [] (Integer 4 []) () ()) ()) (Assert (Compare (Var 2 i) Eq (ConstantInteger 49 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [(ConstantString "1" (Character 1 1 () []))] [] (Integer 4 []) (ConstantInteger 49 (Integer 4 [])) ()) Eq (ConstantInteger 49 (Integer 4 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 20 {}) _lfortran_main_program [] [(SubroutineCall 1 test_ord () [] ()) (SubroutineCall 1 test_chr () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 19 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_chr: (Subroutine (SymbolTable 3 {chr: (ExternalSymbol 3 chr 5 chr lpython_builtin [] chr Private), i: (Variable 3 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 3 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_chr [] [(= (Var 3 i) (ConstantInteger 48 (Integer 4 [])) ()) (= (Var 3 s) (FunctionCall 3 chr () [(Var 3 i)] [] (Character 1 -2 () []) () ()) ()) (Assert (Compare (Var 3 s) Eq (ConstantString "0" (Character 1 1 () [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 3 chr () [(ConstantInteger 48 (Integer 4 []))] [] (Character 1 -2 () []) (ConstantString "0" (Character 1 1 () [])) ()) Eq (ConstantString "0" (Character 1 1 () [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.), test_ord: (Subroutine (SymbolTable 2 {i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), ord: (ExternalSymbol 2 ord 5 ord lpython_builtin [] ord Private), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_ord [] [(= (Var 2 s) (ConstantString "1" (Character 1 1 () [])) ()) (= (Var 2 i) (FunctionCall 2 ord () [(Var 2 s)] [] (Integer 4 []) () ()) ()) (Assert (Compare (Var 2 i) Eq (ConstantInteger 49 (Integer 4 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 ord () [(ConstantString "1" (Character 1 1 () []))] [] (Integer 4 []) (ConstantInteger 49 (Integer 4 [])) ()) Eq (ConstantInteger 49 (Integer 4 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 18 {}) _lfortran_main_program [] [(SubroutineCall 1 test_abs () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 17 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_abs: (Subroutine (SymbolTable 2 {abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), x: (Variable 2 x Local () () Default (Real 8 []) Source Public Required .false.)}) test_abs [] [(= (Var 2 x) (ConstantReal 5.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 x) (UnaryOp USub (ConstantReal 5.500000 (Real 8 [])) (Real 8 []) (ConstantReal -5.500000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 abs () [(ConstantReal 5.500000 (Real 8 []))] [] (Real 8 []) (ConstantReal 5.500000 (Real 8 [])) ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 abs () [(UnaryOp USub (ConstantReal 5.500000 (Real 8 [])) (Real 8 []) (ConstantReal -5.500000 (Real 8 [])))] [] (Real 8 []) (ConstantReal 5.500000 (Real 8 [])) ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) | ||
(TranslationUnit (SymbolTable 1 {_lfortran_main_program: (Subroutine (SymbolTable 19 {}) _lfortran_main_program [] [(SubroutineCall 1 test_abs () [] ())] Source Public Implementation () .false. .false.), lpython_builtin: (IntrinsicModule lpython_builtin), main_program: (Program (SymbolTable 18 {}) main_program [] [(SubroutineCall 1 _lfortran_main_program () [] ())]), test_abs: (Subroutine (SymbolTable 2 {abs: (ExternalSymbol 2 abs 4 abs lpython_builtin [] abs Private), x: (Variable 2 x Local () () Default (Real 8 []) Source Public Required .false.)}) test_abs [] [(= (Var 2 x) (ConstantReal 5.500000 (Real 8 [])) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (= (Var 2 x) (UnaryOp USub (ConstantReal 5.500000 (Real 8 [])) (Real 8 []) (ConstantReal -5.500000 (Real 8 []))) ()) (Assert (Compare (FunctionCall 2 abs () [(Var 2 x)] [] (Real 8 []) () ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) () ()) ()) (Assert (Compare (FunctionCall 2 abs () [(ConstantReal 5.500000 (Real 8 []))] [] (Real 8 []) (ConstantReal 5.500000 (Real 8 [])) ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ()) (Assert (Compare (FunctionCall 2 abs () [(UnaryOp USub (ConstantReal 5.500000 (Real 8 [])) (Real 8 []) (ConstantReal -5.500000 (Real 8 [])))] [] (Real 8 []) (ConstantReal 5.500000 (Real 8 [])) ()) Eq (ConstantReal 5.500000 (Real 8 [])) (Logical 4 []) (ConstantLogical .true. (Logical 4 [])) ()) ())] Source Public Implementation () .false. .false.)}) []) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.