From 6203cadcae3a251ad8b8ed13b4a75b0a31ef6e56 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Fri, 9 Mar 2018 16:16:23 -0800 Subject: [PATCH] Move away from math.log10 and math.pow in Lua generators. Fixes #1695 --- generators/lua/math.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/generators/lua/math.js b/generators/lua/math.js index c104bfc16..b60d023da 100644 --- a/generators/lua/math.js +++ b/generators/lua/math.js @@ -66,9 +66,14 @@ Blockly.Lua['math_single'] = function(block) { Blockly.Lua.ORDER_UNARY) || '0'; return ['-' + arg, Blockly.Lua.ORDER_UNARY]; } - if (operator == 'SIN' || operator == 'COS' || operator == 'TAN') { + if (operator == 'POW10') { arg = Blockly.Lua.valueToCode(block, 'NUM', - Blockly.Lua.ORDER_MULTIPLICATIVE) || '0'; + Blockly.Lua.ORDER_EXPONENTIATION) || '0'; + return ['10 ^ ' + arg, Blockly.Lua.ORDER_EXPONENTIATION]; + } + if (operator == 'ROUND') { + arg = Blockly.Lua.valueToCode(block, 'NUM', + Blockly.Lua.ORDER_ADDITIVE) || '0'; } else { arg = Blockly.Lua.valueToCode(block, 'NUM', Blockly.Lua.ORDER_NONE) || '0'; @@ -84,14 +89,11 @@ Blockly.Lua['math_single'] = function(block) { code = 'math.log(' + arg + ')'; break; case 'LOG10': - code = 'math.log10(' + arg + ')'; + code = 'math.log(' + arg + ', 10)'; break; case 'EXP': code = 'math.exp(' + arg + ')'; break; - case 'POW10': - code = 'math.pow(10,' + arg + ')'; - break; case 'ROUND': // This rounds up. Blockly does not specify rounding direction. code = 'math.floor(' + arg + ' + .5)';