1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the examples of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 ** the names of its contributors may be used to endorse or promote
22 ** products derived from this software without specific prior written
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
46 function disabled(op) {
47 if (op == "." && display.text.toString().search(/\./) != -1) {
49 } else if (op == window.squareRoot && display.text.toString().search(/-/) != -1) {
56 function doOperation(op) {
57 if (op == '*')//Keyboard Aliases
58 op = window.multiplication;
65 if (op.toString().length==1 && ((op >= "0" && op <= "9") || op==".") ) {
66 if (display.text.toString().length >= 14)
67 return; // No arbitrary length numbers
68 if (lastOp.toString().length == 1 && ((lastOp >= "0" && lastOp <= "9") || lastOp == ".") ) {
69 display.text = display.text + op.toString()
78 if (display.currentOperation.text == "+") {
79 display.text = Number(display.text.valueOf()) + Number(curVal.valueOf())
80 } else if (display.currentOperation.text == "-") {
81 display.text = Number(curVal) - Number(display.text.valueOf())
82 } else if (display.currentOperation.text == window.multiplication) {
83 display.text = Number(curVal) * Number(display.text.valueOf())
84 } else if (display.currentOperation.text == window.division) {
85 display.text = Number(Number(curVal) / Number(display.text.valueOf())).toString()
86 } else if (display.currentOperation.text == "=") {
89 if (op == "+" || op == "-" || op == window.multiplication || op == window.division) {
90 display.currentOperation.text = op
91 curVal = display.text.valueOf()
96 display.currentOperation.text = ""
99 display.text = (1 / display.text.valueOf()).toString()
100 } else if (op == "x^2") {
101 display.text = (display.text.valueOf() * display.text.valueOf()).toString()
102 } else if (op == "Abs") {
103 display.text = (Math.abs(display.text.valueOf())).toString()
104 } else if (op == "Int") {
105 display.text = (Math.floor(display.text.valueOf())).toString()
106 } else if (op == window.plusminus) {
107 display.text = (display.text.valueOf() * -1).toString()
108 } else if (op == window.squareRoot) {
109 display.text = (Math.sqrt(display.text.valueOf())).toString()
110 } else if (op == "mc") {
112 } else if (op == "m+") {
113 memory += display.text.valueOf()
114 } else if (op == "mr") {
115 display.text = memory.toString()
116 } else if (op == "m-") {
117 memory = display.text.valueOf()
118 } else if (op == window.leftArrow) {
119 display.text = display.text.toString().slice(0, -1)
120 if (display.text.length == 0) {
123 } else if (op == "Off") {
125 } else if (op == "C") {
127 } else if (op == "AC") {