001: // ============================================================================
002: // $Id: DoubleMath.java,v 1.5 2005/08/02 23:45:06 davidahall Exp $
003: // Copyright (c) 2003-2005 David A. Hall
004: // ============================================================================
005: // The contents of this file are subject to the Common Development and
006: // Distribution License (CDDL), Version 1.0 (the License); you may not use this
007: // file except in compliance with the License. You should have received a copy
008: // of the the License along with this file: if not, a copy of the License is
009: // available from Sun Microsystems, Inc.
010: //
011: // http://www.sun.com/cddl/cddl.html
012: //
013: // From time to time, the license steward (initially Sun Microsystems, Inc.) may
014: // publish revised and/or new versions of the License. You may not use,
015: // distribute, or otherwise make this file available under subsequent versions
016: // of the License.
017: //
018: // Alternatively, the contents of this file may be used under the terms of the
019: // GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
020: // case the provisions of the LGPL are applicable instead of those above. If you
021: // wish to allow use of your version of this file only under the terms of the
022: // LGPL, and not to allow others to use your version of this file under the
023: // terms of the CDDL, indicate your decision by deleting the provisions above
024: // and replace them with the notice and other provisions required by the LGPL.
025: // If you do not delete the provisions above, a recipient may use your version
026: // of this file under the terms of either the CDDL or the LGPL.
027: //
028: // This library is distributed in the hope that it will be useful,
029: // but WITHOUT ANY WARRANTY; without even the implied warranty of
030: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
031: // ============================================================================
032: /**
033: * Provides Arithmetic implementation for Doubles
034: * <p>
035: * Copyright © 2003-2005 David A. Hall
036: *
037: * @author <a href="mailto:dave@dolphin.hallsquared.org">David A. Hall</a>
038: */package net.sf.jga.fn.arithmetic;
039:
040: class DoubleMath implements Arithmetic<Double> {
041:
042: static final long serialVersionUID = 8842457834391281612L;
043:
044: static private final Double ZERO = new Double(0.0d);
045: static private final Double ONE = new Double(1.0d);
046:
047: /**
048: * Returns the given value in the appropriate type
049: * @throws IllegalArgumentException if the value cannot be converted
050: */
051:
052: public Double valueOf(Number value) throws IllegalArgumentException {
053: return new Double(value.doubleValue());
054: }
055:
056: /**
057: * Returns the value 0 of the appropriate type
058: */
059:
060: public Double zero() {
061: return ZERO;
062: }
063:
064: /**
065: * Returns the value 1 of the appropriate type
066: */
067:
068: public Double one() {
069: return ONE;
070: }
071:
072: /**
073: * For numeric arguments x and y, returns x + y
074: * @return the sum of the two arguments
075: */
076:
077: public Double plus(Double x, Double y) {
078: return new Double(x.doubleValue() + y.doubleValue());
079: }
080:
081: /**
082: * For numeric arguments x and y, returns x - y
083: * @return the difference of the two arguments
084: */
085:
086: public Double minus(Double x, Double y) {
087: return new Double(x.doubleValue() - y.doubleValue());
088: }
089:
090: /**
091: * For numeric arguments x and y, returns x * y
092: * @return the product of the two arguments
093: */
094:
095: public Double multiplies(Double x, Double y) {
096: return new Double(x.doubleValue() * y.doubleValue());
097: }
098:
099: /**
100: * for numeric argument x, returns -x
101: * @return the negative of its argument
102: */
103:
104: public Double negate(Double x) {
105: return new Double(-x.doubleValue());
106: }
107:
108: /**
109: * For numeric arguments x and y, returns x / y
110: * @return the quotient of the two arguments
111: */
112:
113: public Double divides(Double x, Double y) {
114: return new Double(x.doubleValue() / y.doubleValue());
115: }
116: }
|