forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the round() function
Issue: 34 in on github Issue: 116 on Google code. Note: For some reason this does not pass the parser test. None of the unit tests I develop ever pass the parser test it might be my local dev envionment. But the unit test is solid and tests the functionality nicely.
- Loading branch information
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,16 @@ | ||
f = 2.515 | ||
g = round(f) | ||
# Deal with skulpt not printing whole floats with a ".0" | ||
if ( g == 3.0 ) : | ||
print "3.0" | ||
else : | ||
print g | ||
g = round(f,1) | ||
print g | ||
g = round(f,2) | ||
print g | ||
g = round(f,3) | ||
print g | ||
g = round(f,4) | ||
print g | ||
|
This file contains 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,5 @@ | ||
3.0 | ||
2.5 | ||
2.52 | ||
2.515 | ||
2.515 |
This file contains 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,42 @@ | ||
Sym_type: module | ||
Sym_name: top | ||
Sym_lineno: 0 | ||
Sym_nested: False | ||
Sym_haschildren: False | ||
-- Identifiers -- | ||
name: f | ||
is_referenced: True | ||
is_imported: False | ||
is_parameter: False | ||
is_global: False | ||
is_declared_global: False | ||
is_local: True | ||
is_free: False | ||
is_assigned: True | ||
is_namespace: False | ||
namespaces: [ | ||
] | ||
name: g | ||
is_referenced: True | ||
is_imported: False | ||
is_parameter: False | ||
is_global: False | ||
is_declared_global: False | ||
is_local: True | ||
is_free: False | ||
is_assigned: True | ||
is_namespace: False | ||
namespaces: [ | ||
] | ||
name: round | ||
is_referenced: True | ||
is_imported: False | ||
is_parameter: False | ||
is_global: True | ||
is_declared_global: False | ||
is_local: False | ||
is_free: False | ||
is_assigned: False | ||
is_namespace: False | ||
namespaces: [ | ||
] |
This file contains 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,79 @@ | ||
Module(body=[Assign(targets=[Name(id='f', | ||
ctx=Store())], | ||
value=Num(n=2.5150000000000001)), | ||
Assign(targets=[Name(id='g', | ||
ctx=Store())], | ||
value=Call(func=Name(id='round', | ||
ctx=Load()), | ||
args=[Name(id='f', | ||
ctx=Load())], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
If(test=Compare(left=Name(id='g', | ||
ctx=Load()), | ||
ops=[Eq()], | ||
comparators=[Num(n=3.0)]), | ||
body=[Print(dest=None, | ||
values=[Str(s='3.0')], | ||
nl=True)], | ||
orelse=[Print(dest=None, | ||
values=[Name(id='g', | ||
ctx=Load())], | ||
nl=True)]), | ||
Assign(targets=[Name(id='g', | ||
ctx=Store())], | ||
value=Call(func=Name(id='round', | ||
ctx=Load()), | ||
args=[Name(id='f', | ||
ctx=Load()), | ||
Num(n=1)], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='g', | ||
ctx=Load())], | ||
nl=True), | ||
Assign(targets=[Name(id='g', | ||
ctx=Store())], | ||
value=Call(func=Name(id='round', | ||
ctx=Load()), | ||
args=[Name(id='f', | ||
ctx=Load()), | ||
Num(n=2)], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='g', | ||
ctx=Load())], | ||
nl=True), | ||
Assign(targets=[Name(id='g', | ||
ctx=Store())], | ||
value=Call(func=Name(id='round', | ||
ctx=Load()), | ||
args=[Name(id='f', | ||
ctx=Load()), | ||
Num(n=3)], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='g', | ||
ctx=Load())], | ||
nl=True), | ||
Assign(targets=[Name(id='g', | ||
ctx=Store())], | ||
value=Call(func=Name(id='round', | ||
ctx=Load()), | ||
args=[Name(id='f', | ||
ctx=Load()), | ||
Num(n=4)], | ||
keywords=[], | ||
starargs=None, | ||
kwargs=None)), | ||
Print(dest=None, | ||
values=[Name(id='g', | ||
ctx=Load())], | ||
nl=True)]) |