/[pcsx2_0.9.7]/trunk/common/include/Utilities/FixedPointTypes.h
ViewVC logotype

Annotation of /trunk/common/include/Utilities/FixedPointTypes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (hide annotations) (download)
Fri Nov 12 01:10:22 2010 UTC (9 years, 9 months ago) by william
File MIME type: text/plain
File size: 2951 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4013 local: v0.9.7.197-latest) in ./trunk
1 william 31 /* PCSX2 - PS2 Emulator for PCs
2     * Copyright (C) 2002-2010 PCSX2 Dev Team
3     *
4     * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5     * of the GNU Lesser General Public License as published by the Free Software Found-
6     * ation, either version 3 of the License, or (at your option) any later version.
7     *
8     * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10     * PURPOSE. See the GNU General Public License for more details.
11     *
12     * You should have received a copy of the GNU General Public License along with PCSX2.
13     * If not, see <http://www.gnu.org/licenses/>.
14     */
15    
16     #pragma once
17    
18     #include "Dependencies.h"
19    
20     template< int Precision >
21     struct FixedInt
22     {
23     s32 Raw;
24    
25 william 62 FixedInt();
26     FixedInt( int signedval );
27     FixedInt( double doubval );
28     FixedInt( float floval );
29 william 31
30 william 62 bool operator ==( const FixedInt<Precision>& right ) const { return Raw == right.Raw; }
31     bool operator !=( const FixedInt<Precision>& right ) const { return Raw != right.Raw; }
32 william 31
33 william 62 bool operator>( const FixedInt<Precision>& right ) const { return Raw > right.Raw; };
34     bool operator>=( const FixedInt<Precision>& right ) const { return Raw >= right.Raw; };
35     bool operator<( const FixedInt<Precision>& right ) const { return Raw < right.Raw; };
36     bool operator<=( const FixedInt<Precision>& right ) const { return Raw <= right.Raw; };
37 william 31
38 william 62 FixedInt<Precision> operator+( const FixedInt<Precision>& right ) const;
39     FixedInt<Precision> operator-( const FixedInt<Precision>& right ) const;
40     FixedInt<Precision>& operator+=( const FixedInt<Precision>& right );
41     FixedInt<Precision>& operator-=( const FixedInt<Precision>& right );
42 william 31
43 william 62 FixedInt<Precision>& ConfineTo( const FixedInt<Precision>& low, const FixedInt<Precision>& high );
44 william 31
45 william 62 FixedInt<Precision> operator*( const FixedInt<Precision>& right ) const;
46     FixedInt<Precision> operator/( const FixedInt<Precision>& right ) const;
47     FixedInt<Precision>& operator*=( const FixedInt<Precision>& right );
48     FixedInt<Precision>& operator/=( const FixedInt<Precision>& right );
49 william 31
50 william 62 static bool OverflowCheck( int signedval );
51     static bool OverflowCheck( double signedval );
52 william 31
53 william 62 int GetWhole() const;
54     int GetFraction() const;
55 william 31
56 william 62 FixedInt<Precision>& SetRaw( s32 rawsrc );
57     FixedInt<Precision>& Round();
58     FixedInt<Precision>& SetWhole( s32 wholepart );
59     FixedInt<Precision>& SetFraction( u32 fracpart );
60 william 31
61 william 62 wxString ToString() const;
62     wxString ToString( int fracDigits ) const;
63 william 31
64 william 62 double ToDouble() const;
65     float ToFloat() const;
66     int ToIntTruncated() const;
67     int ToIntRounded() const;
68 william 31
69 william 62 static bool TryFromString( FixedInt<Precision>& dest, const wxString& parseFrom );
70     static FixedInt<Precision> FromString( const wxString& parseFrom, const FixedInt<Precision>& defval );
71     static FixedInt<Precision> FromString( const wxString parseFrom );
72 william 31 };
73    
74     typedef FixedInt<256> Fixed256;
75     typedef FixedInt<100> Fixed100;

  ViewVC Help
Powered by ViewVC 1.1.22