Improve javadoc for ctfAdapter in Tmf.Core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / FloatDefinition.java
index cdb0a52797069e914a9200fbb870554a83ed71d9..07bd50cd39364184c577a4e14625172162db62cc 100644 (file)
@@ -13,6 +13,11 @@ package org.eclipse.linuxtools.ctf.core.event.types;
 
 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
 
+/**
+ * Float definition
+ * @author Matthew Khouzam
+ *
+ */
 public class FloatDefinition extends Definition {
     // ------------------------------------------------------------------------
     // Attributes
@@ -25,23 +30,47 @@ public class FloatDefinition extends Definition {
     // Contructors
     // ------------------------------------------------------------------------
 
+    /**
+     * Constructor
+     *
+     * @param declaration
+     *            the parent declaration
+     * @param definitionScope
+     *            the parent scope
+     * @param fieldName
+     *            the field name
+     */
     public FloatDefinition(FloatDeclaration declaration,
             IDefinitionScope definitionScope, String fieldName) {
         super(definitionScope, fieldName);
         this.declaration = declaration;
     }
+
     // ------------------------------------------------------------------------
     // Gettters/Setters/Predicates
     // ------------------------------------------------------------------------
 
+    /**
+     * THe value of a float stored, fit into a double. This should be extended
+     * for exotic floats if this is necessary.
+     *
+     * @return the value of the float field fit into a double.
+     */
     public double getValue() {
         return value;
     }
 
+    /**
+     * Sets the value of the float
+     *
+     * @param val
+     *            the value of the float
+     */
     public void setValue(double val) {
         value = val;
     }
 
+    @Override
     public FloatDeclaration getDeclaration() {
         return declaration;
     }
@@ -50,36 +79,27 @@ public class FloatDefinition extends Definition {
     // Operations
     // ------------------------------------------------------------------------
 
-
-
     @Override
     public void read(BitBuffer input) {
         int exp = declaration.getExponent();
         int mant = declaration.getMantissa();
-        if( (exp + mant) == 32 ){
-            readRawFloat32(input, mant , exp);
-        }
-        else if((exp + mant) == 64)
-        {
-            readRawFloat64(input, mant,exp);
-        }
-        else
-        {
+        if ((exp + mant) == 32) {
+            value = readRawFloat32(input, mant, exp);
+        } else if ((exp + mant) == 64) {
+            value = readRawFloat64(input, mant, exp);
+        } else {
             value = Double.NaN;
         }
     }
 
-
-
-    private void readRawFloat64(BitBuffer input, final int manBits, final int expBits) {
-       long low = input.getInt(32, false);
-       low = low & 0x00000000FFFFFFFFL;
-       long high = input.getInt(32, false);
-       high = high & 0x00000000FFFFFFFFL;
-       long temp = (high << 32) | low;
-
-
-       value = createFloat(temp, manBits, expBits);
+    private static double readRawFloat64(BitBuffer input, final int manBits,
+            final int expBits) {
+        long low = input.getInt(32, false);
+        low = low & 0x00000000FFFFFFFFL;
+        long high = input.getInt(32, false);
+        high = high & 0x00000000FFFFFFFFL;
+        long temp = (high << 32) | low;
+        return createFloat(temp, manBits - 1, expBits);
     }
 
     /**
@@ -87,26 +107,26 @@ public class FloatDefinition extends Definition {
      * @param manBits
      * @param expBits
      */
-    private static double createFloat(long rawValue, final int manBits, final int expBits) {
-        long manShift = 1L << manBits;
-           long manMask = manShift -1;
-           long expMask = (1L << expBits) -1;
-
-           int exp =(int)( rawValue >> manBits);
-           long man  = (rawValue & manMask);
-           double expPow = Math.pow(2.0, exp-(1 << (expBits-1)));
-           double ret = man * 1.0f;
-           ret /= manShift;
-           ret += 1.0;
-           ret *= expPow;
-           return ret;
+    private static double createFloat(long rawValue, final int manBits,
+            final int expBits) {
+        long manShift = 1L << (manBits);
+        long manMask = manShift - 1;
+        long expMask = (1L << expBits) - 1;
+
+        int exp = (int) ((rawValue >> (manBits)) & expMask) + 1;
+        long man = (rawValue & manMask);
+        double expPow = Math.pow(2.0, exp - (1 << (expBits - 1)));
+        double ret = man * 1.0f;
+        ret /= manShift;
+        ret += 1.0;
+        ret *= expPow;
+        return ret;
     }
 
-    private void readRawFloat32(BitBuffer input, final int manBits,
-    final int expBits) {
+    private static double readRawFloat32(BitBuffer input, final int manBits,
+            final int expBits) {
         long temp = input.getInt(32, false);
-
-        value = createFloat(temp, manBits, expBits);
+        return createFloat(temp, manBits - 1, expBits);
     }
 
     @Override
This page took 0.025914 seconds and 5 git commands to generate.