One of my students unwittingly discovered a bug with GlowScript 3.1 on Trinket.io. This bug does not seem to happen in my testing on
glowscript.org with 3.0, 3.1, or 3.2.
The bug was discovered while using the built-in
abs to make sure the returned value from the function. It appears the problem is how variables are being returned from the function (and not
abs). Example code below showing the bug:
GlowScript 3.1 VPython
def f(x):
f = x + 0.0001
return(f)
v1 = 2432.0
v2 = -1432.0
v3 = -0.495
print("abs(v1) = ", abs(v1))
print("abs(v2) = ", abs(v2))
print("abs(v3) = ", abs(v3))
print("abs(v1) = ", abs(f(v1)))
print("abs(v2) = ", abs(f(v2)))
print("abs(v3) = ", abs(f(v3)))
The bottom set of code when returned from a function gives NaN as results. If I change to 3.0, then it works fine (GlowScript 3.2 is not available yet on Trinket).
This seems to be something tied to returning the value of the function since you can do print("abs(v1) = ", abs(f(v1)))
print("abs(v2) = ", abs(f(v2)))
print("abs(v3) = ", int(f(v3)))
which gives an error and won't run:
Invalid literal for int with base 10: [object Promise]