Fix infinity in Python, PHP, and Dart.

This commit is contained in:
Neil Fraser
2015-10-24 23:50:39 -04:00
parent 0aa1da6dd4
commit 2f30034983
6 changed files with 33 additions and 10 deletions

View File

@@ -35,8 +35,17 @@ Blockly.Python.addReservedWords('math,random');
Blockly.Python['math_number'] = function(block) {
// Numeric value.
var code = parseFloat(block.getFieldValue('NUM'));
var order = code < 0 ? Blockly.Python.ORDER_UNARY_SIGN :
Blockly.Python.ORDER_ATOMIC;
var order;
if (code == Infinity) {
code = 'float("inf")';
order = Blockly.Python.ORDER_FUNCTION_CALL;
} else if (code == -Infinity) {
code = '-float("inf")';
order = Blockly.Python.ORDER_UNARY_SIGN;
} else {
order = code < 0 ? Blockly.Python.ORDER_UNARY_SIGN :
Blockly.Python.ORDER_ATOMIC;
}
return [code, order];
};