/[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 62 - (hide annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 2975 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug 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     #include "Exceptions.h"
20    
21     template< int Precision >
22     struct FixedInt
23     {
24     s32 Raw;
25    
26 william 62 FixedInt();
27     FixedInt( int signedval );
28     FixedInt( double doubval );
29     FixedInt( float floval );
30 william 31
31 william 62 bool operator ==( const FixedInt<Precision>& right ) const { return Raw == right.Raw; }
32     bool operator !=( const FixedInt<Precision>& right ) const { return Raw != right.Raw; }
33 william 31
34 william 62 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     bool operator<=( const FixedInt<Precision>& right ) const { return Raw <= right.Raw; };
38 william 31
39 william 62 FixedInt<Precision> operator+( const FixedInt<Precision>& right ) const;
40     FixedInt<Precision> operator-( const FixedInt<Precision>& right ) const;
41     FixedInt<Precision>& operator+=( const FixedInt<Precision>& right );
42     FixedInt<Precision>& operator-=( const FixedInt<Precision>& right );
43 william 31
44 william 62 FixedInt<Precision>& ConfineTo( const FixedInt<Precision>& low, const FixedInt<Precision>& high );
45 william 31
46 william 62 FixedInt<Precision> operator*( const FixedInt<Precision>& right ) const;
47     FixedInt<Precision> operator/( const FixedInt<Precision>& right ) const;
48     FixedInt<Precision>& operator*=( const FixedInt<Precision>& right );
49     FixedInt<Precision>& operator/=( const FixedInt<Precision>& right );
50 william 31
51 william 62 static bool OverflowCheck( int signedval );
52     static bool OverflowCheck( double signedval );
53 william 31
54 william 62 int GetWhole() const;
55     int GetFraction() const;
56 william 31
57 william 62 FixedInt<Precision>& SetRaw( s32 rawsrc );
58     FixedInt<Precision>& Round();
59     FixedInt<Precision>& SetWhole( s32 wholepart );
60     FixedInt<Precision>& SetFraction( u32 fracpart );
61 william 31
62 william 62 wxString ToString() const;
63     wxString ToString( int fracDigits ) const;
64 william 31
65 william 62 double ToDouble() const;
66     float ToFloat() const;
67     int ToIntTruncated() const;
68     int ToIntRounded() const;
69 william 31
70 william 62 static bool TryFromString( FixedInt<Precision>& dest, const wxString& parseFrom );
71     static FixedInt<Precision> FromString( const wxString& parseFrom, const FixedInt<Precision>& defval );
72     static FixedInt<Precision> FromString( const wxString parseFrom );
73 william 31 };
74    
75     typedef FixedInt<256> Fixed256;
76     typedef FixedInt<100> Fixed100;

  ViewVC Help
Powered by ViewVC 1.1.22