Times.java revision 608:7e06bf1dcb09
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. 31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41541Srgrimes * 51541Srgrimes * This code is free software; you can redistribute it and/or modify it 61541Srgrimes * under the terms of the GNU General Public License version 2 only, as 71541Srgrimes * published by the Free Software Foundation. Oracle designates this 81541Srgrimes * particular file as subject to the "Classpath" exception as provided 91541Srgrimes * by Oracle in the LICENSE file that accompanied this code. 101541Srgrimes * 111541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 121541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 131541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 141541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 151541Srgrimes * accompanied this code). 161541Srgrimes * 171541Srgrimes * You should have received a copy of the GNU General Public License version 181541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 191541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 201541Srgrimes * 211541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 221541Srgrimes * or visit www.oracle.com if you need additional information or have any 231541Srgrimes * questions. 241541Srgrimes */ 251541Srgrimes/* 261541Srgrimes * COMPONENT_NAME: idl.parser 271541Srgrimes * 281541Srgrimes * ORIGINS: 27 291541Srgrimes * 301541Srgrimes * Licensed Materials - Property of IBM 311541Srgrimes * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999 321541Srgrimes * RMI-IIOP v1.0 331541Srgrimes * 341541Srgrimes */ 351541Srgrimes 361541Srgrimespackage com.sun.tools.corba.se.idl.constExpr; 371541Srgrimes 381541Srgrimes// NOTES: 3950477Speter 401541Srgrimesimport com.sun.tools.corba.se.idl.Util; 411541Srgrimesimport java.math.BigInteger; 422165Spaul 432165Spaulpublic class Times extends BinaryExpr 442165Spaul{ 4529683Sgibbs protected Times (Expression leftOperand, Expression rightOperand) 4629683Sgibbs { 4729683Sgibbs super ("*", leftOperand, rightOperand); 4829683Sgibbs } // ctor 4929683Sgibbs 501541Srgrimes public Object evaluate () throws EvaluationException 5129683Sgibbs { 5229683Sgibbs try 5329683Sgibbs { 5429683Sgibbs Number l = (Number)left ().evaluate (); 5531470Sdg Number r = (Number)right ().evaluate (); 561541Srgrimes 571541Srgrimes boolean lIsNonInteger = l instanceof Float || l instanceof Double; 5844510Swollman boolean rIsNonInteger = r instanceof Float || r instanceof Double; 591541Srgrimes 601541Srgrimes if (lIsNonInteger && rIsNonInteger) 6144510Swollman value (new Double (l.doubleValue () * r.doubleValue ())); 6244510Swollman else if (lIsNonInteger || rIsNonInteger) 6344510Swollman { 6444510Swollman String[] parameters = {Util.getMessage ("EvaluationException.times"), left ().value ().getClass ().getName (), right ().value ().getClass ().getName ()}; 6529683Sgibbs throw new EvaluationException (Util.getMessage ("EvaluationException.1", parameters)); 6629683Sgibbs } 6729683Sgibbs else 6829683Sgibbs { 691541Srgrimes // Multiplication (*) 7029683Sgibbs BigInteger tmpL = (BigInteger)l, tmpR = (BigInteger)r; 7129683Sgibbs value (tmpL.multiply (tmpR)); 722112Swollman //daz value (new Long (l.longValue () * r.longValue ())); 7329683Sgibbs } 7432412Sphk } 7544510Swollman catch (ClassCastException e) 7644510Swollman { 7744510Swollman String[] parameters = {Util.getMessage ("EvaluationException.times"), left ().value ().getClass ().getName (), right ().value ().getClass ().getName ()}; 7844510Swollman throw new EvaluationException (Util.getMessage ("EvaluationException.1", parameters)); 7944510Swollman } 8044510Swollman return value (); 8144510Swollman } // evaluate 8244510Swollman} // class Times 8329683Sgibbs