00001 /* 00002 * Float64.hpp 00003 * 00004 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_FLOAT64_HPP 00017 #define COH_FLOAT64_HPP 00018 00019 #include "coherence/lang/compatibility.hpp" 00020 00021 #include "coherence/lang/Number.hpp" 00022 #include "coherence/lang/Primitive.hpp" 00023 #include "coherence/lang/TypedHandle.hpp" 00024 00025 COH_OPEN_NAMESPACE2(coherence,lang) 00026 00027 00028 /** 00029 * An immutable 64-bit floating-point value. 00030 * 00031 * @author jh 2008.04.01 00032 */ 00033 class COH_EXPORT Float64 00034 : public cloneable_spec<Float64, 00035 extends<Primitive<float64_t> >, 00036 implements<Number, Comparable> > 00037 { 00038 friend class factory<Float64>; 00039 00040 // ----- constructors --------------------------------------------------- 00041 00042 private: 00043 /** 00044 * Create a new Float64 instance. 00045 * 00046 * @param dfl the value of the new Float64 00047 */ 00048 Float64(float64_t dfl); 00049 00050 /** 00051 * Copy constructor. 00052 */ 00053 Float64(const Float64& that); 00054 00055 00056 // ----- Float64 interface ---------------------------------------------- 00057 00058 public: 00059 /** 00060 * Return a <code>uint64_t</code> representation of the specified 00061 * 64-bit floating point value according to the IEEE 754 00062 * floating-point "double format" bit layout. 00063 * 00064 * @param dfl a 64-bit floating-point number 00065 * 00066 * @return the <code>uint64_t</code> representation of the 00067 * floating-point number 00068 */ 00069 static uint64_t float64ToBits(float64_t dfl); 00070 00071 /** 00072 * Return the <code>float64_t</code> value corresponding to a given 00073 * bit representation. The argument is considered to be a representation 00074 * of a 64-bit floating-point value according to the IEEE 754 00075 * floating-point "double format" bit layout. 00076 * 00077 * @param l a 64-bit unsigned integer containing the bit 00078 * representation of the floating-point number 00079 * 00080 * @return the <code>float64_t</code> floating-point value with the 00081 * same bit pattern. 00082 */ 00083 static float64_t bitsToFloat64(uint64_t l); 00084 00085 00086 // ----- Number interface ----------------------------------------------- 00087 00088 public: 00089 /** 00090 * {@inheritDoc} 00091 */ 00092 virtual int16_t getInt16Value() const; 00093 00094 /** 00095 * {@inheritDoc} 00096 */ 00097 virtual int32_t getInt32Value() const; 00098 00099 /** 00100 * {@inheritDoc} 00101 */ 00102 virtual int64_t getInt64Value() const; 00103 00104 /** 00105 * {@inheritDoc} 00106 */ 00107 virtual float32_t getFloat32Value() const; 00108 00109 /** 00110 * {@inheritDoc} 00111 */ 00112 virtual float64_t getFloat64Value() const; 00113 00114 00115 // ----- Comparable interface ------------------------------------------- 00116 00117 public: 00118 /** 00119 * {@inheritDoc} 00120 */ 00121 virtual int32_t compareTo(Object::View v) const; 00122 00123 00124 // ----- Object interface ----------------------------------------------- 00125 00126 public: 00127 /** 00128 * {@inheritDoc} 00129 */ 00130 virtual bool equals(Object::View v) const; 00131 00132 /** 00133 * {@inheritDoc} 00134 */ 00135 virtual size32_t hashCode() const; 00136 00137 00138 // ----- static methods ------------------------------------------------- 00139 00140 public: 00141 /** 00142 * Factory method to produce Float64 objects with an optimization 00143 * that uses cached objects for all common numbers. 00144 * 00145 * @param dfl a float64_t 00146 * 00147 * @return a Float64 whose value is the passed float64_t 00148 */ 00149 static Handle valueOf(float64_t fl); 00150 00151 /** 00152 * Test whether the given float64_t is a NaN. 00153 * 00154 * @param dfl a float64_t to test 00155 * 00156 * @return true if the given float64_t is a Nan, else return false 00157 */ 00158 static bool isNaN(float64_t dfl); 00159 00160 /** 00161 * Test whether the given float64_t is -0.0 or 0.0. 00162 * 00163 * @param dfl a float64_t to test 00164 * 00165 * @return true if the given float64_t is a zero, else return false 00166 */ 00167 static bool isZero(float64_t dfl); 00168 00169 /** 00170 * Test whether the given float64_t is -infinity or +infinity 00171 * 00172 * @param dfl a float64_t to test 00173 * 00174 * @return true if the given float64_t is infinity else return false 00175 */ 00176 static bool isInfinite(float64_t dfl); 00177 00178 /** 00179 * Compare the given float32_t values for order. Return a negative 00180 * integer, zero, or a positive integer if the left value is 00181 * less than, equal to, or greater than the right. The comparison 00182 * is based on the following order: 00183 * -infinity < -0.0 < +0.0 < +infinity < NaN 00184 * 00185 * @param dfll the left hand value to be compared 00186 * @param dflr the right hand value to be compared 00187 * 00188 * 00189 * @return a negative integer, zero, or a positive integer if the 00190 * left value is less than, equal to, or greater than the 00191 * right value 00192 */ 00193 static int32_t compare(float64_t dfll, float64_t dflr); 00194 00195 // ---- constants ------------------------------------------------------- 00196 00197 public: 00198 /** 00199 * Return a constant holding the Not-a-Number (NaN) value of type 00200 * <code>float64_t</code>. It is equivalent to the value returned by 00201 * <code>Float64::bitsToFloat64(((uint64_t) 0x7FF80000) << 32)</code>. 00202 * 00203 * @return the <code>float64_t</code> NaN value 00204 */ 00205 static float64_t getNaN(); 00206 00207 /** 00208 * Return a constant holding the positive infinity value of type 00209 * <code>float64_t</code>. It is equal to the value returned by 00210 * <code>Float64::bitsToFloat64(((uint64_t) 0x7FF00000) << 32)</code>. 00211 * 00212 * @return the <code>float64_t</code> positive infinity value 00213 */ 00214 static float64_t getPositiveInfinity(); 00215 00216 /** 00217 * Returns a constant holding the negative infinity value of type 00218 * <code>float64_t</code>. It is equal to the value returned by 00219 * <code>Float64::bitsToFloat64(((uint64_t) 0xFFF00000) << 32)</code>. 00220 * 00221 * @return the <code>float64_t</code> negative infinity value 00222 */ 00223 static float64_t getNegativeInfinity(); 00224 }; 00225 00226 COH_CLOSE_NAMESPACE2 00227 00228 #endif // COH_FLOAT64_HPP