00001 /* 00002 * Float32.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_FLOAT32_HPP 00017 #define COH_FLOAT32_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 32-bit floating-point value. 00030 * 00031 * @author jh 2008.04.01 00032 */ 00033 class COH_EXPORT Float32 00034 : public cloneable_spec<Float32, 00035 extends<Primitive<float32_t> >, 00036 implements<Number, Comparable> > 00037 { 00038 friend class factory<Float32>; 00039 00040 // ----- constructors --------------------------------------------------- 00041 00042 private: 00043 /** 00044 * Create a new Float32 instance. 00045 * 00046 * @param fl the value of the new Float32 00047 * 00048 * @return the new Float32 00049 */ 00050 Float32(float32_t fl); 00051 00052 /** 00053 * Copy constructor. 00054 */ 00055 Float32(const Float32& that); 00056 00057 00058 // ----- Float32 interface ---------------------------------------------- 00059 00060 public: 00061 /** 00062 * Return a <code>uint32_t</code> representation of the specified 00063 * 32-bit floating point value according to the IEEE 754 00064 * floating-point "single format" bit layout. 00065 * 00066 * @param fl a 32-bit floating-point number 00067 * 00068 * @return the <code>uint32_t</code> representation of the 00069 * floating-point number 00070 */ 00071 static uint32_t float32ToBits(float32_t fl); 00072 00073 /** 00074 * Return the <code>float32_t</code> value corresponding to a given 00075 * bit representation. The argument is considered to be a representation 00076 * of a 32-bit floating-point value according to the IEEE 754 00077 * floating-point "single format" bit layout. 00078 * 00079 * @param n a 32-bit unsigned integer containing the bit 00080 * representation of the floating-point number 00081 * 00082 * @return the <code>float32_t</code> floating-point value with the 00083 * same bit pattern. 00084 */ 00085 static float32_t bitsToFloat32(uint32_t n); 00086 00087 00088 // ----- Number interface ----------------------------------------------- 00089 00090 public: 00091 /** 00092 * {@inheritDoc} 00093 */ 00094 virtual int16_t getInt16Value() const; 00095 00096 /** 00097 * {@inheritDoc} 00098 */ 00099 virtual int32_t getInt32Value() const; 00100 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual int64_t getInt64Value() const; 00105 00106 /** 00107 * {@inheritDoc} 00108 */ 00109 virtual float32_t getFloat32Value() const; 00110 00111 /** 00112 * {@inheritDoc} 00113 */ 00114 virtual float64_t getFloat64Value() const; 00115 00116 00117 // ----- Comparable interface ------------------------------------------- 00118 00119 public: 00120 /** 00121 * {@inheritDoc} 00122 */ 00123 virtual int32_t compareTo(Object::View v) const; 00124 00125 00126 // ----- Object interface ----------------------------------------------- 00127 00128 public: 00129 /** 00130 * {@inheritDoc} 00131 */ 00132 virtual bool equals(Object::View v) const; 00133 00134 /** 00135 * {@inheritDoc} 00136 */ 00137 virtual size32_t hashCode() const; 00138 00139 00140 // ----- static methods ------------------------------------------------ 00141 00142 public: 00143 /** 00144 * Factory method to produce Float32 objects with an optimization 00145 * that uses cached objects for all common numbers. 00146 * 00147 * @param fl a float32_t 00148 * 00149 * @return a Float32 whose value is the passed float32_t 00150 */ 00151 static Handle valueOf(float32_t fl); 00152 00153 /** 00154 * Test whether the given float32_t is a NaN. 00155 * 00156 * @param fl a float32_t to test 00157 * 00158 * @return true if the given float32_t is a NaN, else return false 00159 */ 00160 static bool isNaN(float32_t fl); 00161 00162 /** 00163 * Test whether the given float32_t is -0.0 or 0.0. 00164 * 00165 * @param fl a float32_t to test 00166 * 00167 * @return true if the given float32_t is a zero, else return false 00168 */ 00169 static bool isZero(float32_t fl); 00170 00171 /** 00172 * Test whether the given float32_t is -infinity or +infinity. 00173 * 00174 * @param fl a float32_t to test 00175 * 00176 * @return true if the given float32_t is infinite else return false 00177 */ 00178 static bool isInfinite(float32_t fl); 00179 00180 /** 00181 * Compare the given float32_t values for order. Return a negative 00182 * integer, zero, or a positive integer if the left value is 00183 * less than, equal to, or greater than the right. The comparison 00184 * is based on the following order: 00185 * -infinity < -0.0 < +0.0 < +infinity < NaN 00186 * 00187 * @param fll the left hand value to be compared 00188 * @param flr the right hand value to be compared 00189 * 00190 * @return a negative integer, zero, or a positive integer if the 00191 * left value is less than, equal to, or greater than the 00192 * right value 00193 */ 00194 static int32_t compare(float32_t fll, float32_t flr); 00195 00196 // ---- constants ------------------------------------------------------- 00197 00198 public: 00199 /** 00200 * Return a constant holding the Not-a-Number (NaN) value of type 00201 * <code>float32_t</code>. It is equivalent to the value returned by 00202 * <code>Float32::bitsToFloat32(0x7FC00000)</code>. 00203 * 00204 * @return the <code>float32_t</code> NaN value 00205 */ 00206 static float32_t getNaN(); 00207 00208 /** 00209 * Return a constant holding the positive infinity value of type 00210 * <code>float32_t</code>. It is equal to the value returned by 00211 * <code>Float32::bitsToFloat32(0x7F800000)</code>. 00212 * 00213 * @return the <code>float32_t</code> positive infinity value 00214 */ 00215 static float32_t getPositiveInfinity(); 00216 00217 /** 00218 * Returns a constant holding the negative infinity value of type 00219 * <code>float32_t</code>. It is equal to the value returned by 00220 * <code>Float32::bitsToFloat(0xFF800000)</code>. 00221 * 00222 * @return the <code>float32_t</code> negative infinity value 00223 */ 00224 static float32_t getNegativeInfinity(); 00225 }; 00226 00227 COH_CLOSE_NAMESPACE2 00228 00229 #endif // COH_FLOAT32_HPP