C++ Client API Reference for Oracle Coherence
14c (14.1.2.0.0)

F79659-03

coherence/lang/Float32.hpp

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