Skip to content

Commit 2523e0f

Browse files
committed
Updated round function
1 parent f9615e0 commit 2523e0f

7 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎GlowScriptOffline/glowscript_libraries/RScompiler.3.2.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GlowScriptOffline/glowscript_libraries/compiler.3.2.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎GlowScriptOffline3.2.zip‎

198 Bytes
Binary file not shown.

‎docs/VPythonDocs/math.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h1 class="Heading-1"> <font color="#0000A0">Math Functions</font></h1>
5757
ceil(x)&nbsp;&nbsp;&nbsp;&nbsp;# round up to nearest integer<br />
5858
floor(x)&nbsp;&nbsp;&nbsp;# round down to nearest integer<br />
5959
sign(x) &nbsp;&nbsp;&nbsp;# +1 if x &gt; 0, -1 if x &lt; 0, 0 if x == 0<br />
60-
round(x) &nbsp;&nbsp;# round to nearest integer <br />
60+
round(x,N)&nbsp;# round x to nearest integer; optional N decimal places&nbsp; <br />
6161
max(x,y,z) # the largest of x,y,z<br />
6262
min(x,y,z) # the smallest of x,y,z<br />
6363
random() &nbsp;&nbsp;# pseudorandom number 0 to 1<br />

‎lib/compiling/GScompiler.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ where compile() was called, in untrusted/run.js.
225225
var delim = '"'
226226

227227
var lineno_string = 'ρσ_ls = ' // prepended to quoted line number; used in error return
228+
let language = null
228229

229230
function findrightparen(s) { // s is a string starting with '('; return location of matching ')' or null
230231
// The string may contain string_insert, which represents (.
@@ -243,6 +244,7 @@ where compile() was called, in untrusted/run.js.
243244
}
244245

245246
function preprocess(program, lang) { // manipulate the program source
247+
language = lang
246248
// The preprocessing includes inserting ρσ_ls = "line number" to enable error reporting of original source line
247249
if (lang == 'rapydscript') throw new Error("GlowScript RapydScript is not available after GlowScript 2.9.Choose GlowScript VPython instead.")
248250
if (lang == 'vpython') classinstances.push('self')
@@ -1244,6 +1246,12 @@ where compile() was called, in untrusted/run.js.
12441246

12451247
let s = "scene = canvas();\n"
12461248
let sc = program.indexOf(s) + s.length
1249+
1250+
if (language == 'vpython' && program.indexOf('round') >= 0) { // JavaScript Math.round has only 1 argument
1251+
let ls = "\n function round(num, n=0) {return Number(num.toFixed(n))}\n"
1252+
program = program.slice(0,sc)+ls+program.slice(sc,program.length)
1253+
sc += ls.length
1254+
}
12471255

12481256
if (loadfonts) { // if text object is in user program
12491257
s = " fontloading();\n await waitforfonts();\n" // wait for font files
@@ -1277,7 +1285,7 @@ where compile() was called, in untrusted/run.js.
12771285
// let i = program.search('"2";')
12781286
// let i = program.search('async function __main__')
12791287
// console.log(program.slice(i))
1280-
//console.log(program)
1288+
console.log(program)
12811289
return program
12821290
} // end of compile function
12831291
window.glowscript_compile = compile

‎package/RScompiler.3.2.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package/compiler.3.2.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)