| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class Tape { | 5 class Tape { |
| 6 static final int OP_NOOP = 0; | 6 static final int OP_NOOP = 0; |
| 7 static final int OP_PLUS = 1; | 7 static final int OP_PLUS = 1; |
| 8 static final int OP_MINUS = 2; | 8 static final int OP_MINUS = 2; |
| 9 static final int OP_MULTI = 3; | 9 static final int OP_MULTI = 3; |
| 10 static final int OP_DIV = 4; | 10 static final int OP_DIV = 4; |
| 11 static final int OP_EQUAL = 5; | 11 static final int OP_EQUAL = 5; |
| 12 static final int OP_CLEAR = 6; | 12 static final int OP_CLEAR = 6; |
| 13 | 13 |
| 14 Tape() { | 14 Tape() { |
| 15 clearTape(); | 15 clearTape(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void addToTape(int op, String number) { | 18 void addToTape(int op, String number) { |
| 19 double displayTotal; | 19 double displayTotal; |
| 20 double numberAsValue; | 20 double numberAsValue; |
| 21 | 21 |
| 22 if (number != "." && number != "-" && number != "-.") { | 22 if (number != "." && number != "-" && number != "-.") { |
| 23 try { | 23 try { |
| 24 numberAsValue = Math.parseDouble(number.length == 0 ? "0" : number); | 24 numberAsValue = Math.parseDouble(number.length == 0 ? "0" : number); |
| 25 } on FormatException (e) { | 25 } on FormatException catch (e) { |
| 26 displayError(e.toString()); | 26 displayError(e.toString()); |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 } else { | 29 } else { |
| 30 // Display just the . | 30 // Display just the . |
| 31 displayTotal = total; | 31 displayTotal = total; |
| 32 numberAsValue = 0.0; | 32 numberAsValue = 0.0; |
| 33 } | 33 } |
| 34 | 34 |
| 35 String opAsStr; | 35 String opAsStr; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 234 |
| 235 DivElement get activeInput() => window.document.query("#activeInput"); | 235 DivElement get activeInput() => window.document.query("#activeInput"); |
| 236 DivElement get activeTotal() => window.document.query("#activeTotal"); | 236 DivElement get activeTotal() => window.document.query("#activeTotal"); |
| 237 | 237 |
| 238 void clear() { | 238 void clear() { |
| 239 final element = new Element.tag('div'); | 239 final element = new Element.tag('div'); |
| 240 element.innerHTML = tapeUI.clearCalculation(); | 240 element.innerHTML = tapeUI.clearCalculation(); |
| 241 tapeUI.tape.elements.add(element.elements[0]); | 241 tapeUI.tape.elements.add(element.elements[0]); |
| 242 } | 242 } |
| 243 } | 243 } |
| OLD | NEW |