svgtopt/nvgdecoder/src/FloatFixPt.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  NVG Decoder source file
       
    15  *
       
    16 */
       
    17 #include "FloatFixPt.h"
       
    18 
       
    19 //==============================floatfixpt functions============================
       
    20 // ==========================================================================
       
    21 // Constructor, default to zero
       
    22 // ==========================================================================
       
    23 TFloatFixPt::TFloatFixPt() : iValue(0)
       
    24     {
       
    25     }
       
    26 
       
    27 // ==========================================================================
       
    28 // Constructor
       
    29 // ==========================================================================
       
    30 
       
    31 TFloatFixPt::TFloatFixPt(TInt aVal)
       
    32     {
       
    33     iValue = (aVal << KFixPtFrac);
       
    34     }
       
    35 // ==========================================================================
       
    36 // Constructor
       
    37 // ==========================================================================
       
    38  TFloatFixPt::TFloatFixPt(TInt32 aVal)
       
    39     {
       
    40     iValue = (aVal << KFixPtFrac);
       
    41     }
       
    42  TFloatFixPt::TFloatFixPt(TInt aVal, TBool /*a*/)
       
    43     {
       
    44     iValue = aVal;
       
    45     }
       
    46 // ==========================================================================
       
    47 // Constructor
       
    48 // ==========================================================================
       
    49  TFloatFixPt::TFloatFixPt(TReal32 aVal)
       
    50 {
       
    51     iValue = svgScalarFromFloat(aVal);
       
    52 }
       
    53 
       
    54 // ==========================================================================
       
    55 // Assignment operator
       
    56 // ==========================================================================
       
    57  TFloatFixPt& TFloatFixPt::operator=(TReal32 aVal)
       
    58 {
       
    59     iValue = svgScalarFromFloat(aVal);
       
    60     return *this;
       
    61 }
       
    62 
       
    63  void TFloatFixPt::copyfloatfix(TInt aVal)
       
    64 {
       
    65 	iValue = aVal;
       
    66 }
       
    67 // ==========================================================================
       
    68 // Round to the nearest whole number
       
    69 // ==========================================================================
       
    70  TInt32 TFloatFixPt::Round()
       
    71     {
       
    72     if (0 != (iValue & 0x8000))
       
    73         return (iValue >> KFixPtFrac) + 1;
       
    74     else
       
    75         return (iValue >> KFixPtFrac);
       
    76     }
       
    77 // ===================================================================
       
    78 // Addition operation
       
    79 // ==========================================================================
       
    80  TFloatFixPt TFloatFixPt::operator+(const TFloatFixPt& aVal) const
       
    81     {
       
    82     return TFloatFixPt(iValue + aVal.iValue, ETrue);
       
    83     }
       
    84 //==============================floatfixpt functions============================
       
    85 
       
    86  TFloatFixPt::operator TReal32() const
       
    87 {
       
    88     return ((TReal32) iValue) / KFixPtFracVal;
       
    89 
       
    90 }
       
    91 // ==========================================================================
       
    92 // Get 32-bit representation
       
    93 // ==========================================================================
       
    94  TInt32 TFloatFixPt::RawData()
       
    95     {
       
    96     return iValue;
       
    97     }    
       
    98  //--------------------------------EndOfFile------------------------------------