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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (show 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 /* 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 FixedInt();
26 FixedInt( int signedval );
27 FixedInt( double doubval );
28 FixedInt( float floval );
29
30 bool operator ==( const FixedInt<Precision>& right ) const { return Raw == right.Raw; }
31 bool operator !=( const FixedInt<Precision>& right ) const { return Raw != right.Raw; }
32
33 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
38 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
43 FixedInt<Precision>& ConfineTo( const FixedInt<Precision>& low, const FixedInt<Precision>& high );
44
45 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
50 static bool OverflowCheck( int signedval );
51 static bool OverflowCheck( double signedval );
52
53 int GetWhole() const;
54 int GetFraction() const;
55
56 FixedInt<Precision>& SetRaw( s32 rawsrc );
57 FixedInt<Precision>& Round();
58 FixedInt<Precision>& SetWhole( s32 wholepart );
59 FixedInt<Precision>& SetFraction( u32 fracpart );
60
61 wxString ToString() const;
62 wxString ToString( int fracDigits ) const;
63
64 double ToDouble() const;
65 float ToFloat() const;
66 int ToIntTruncated() const;
67 int ToIntRounded() const;
68
69 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 };
73
74 typedef FixedInt<256> Fixed256;
75 typedef FixedInt<100> Fixed100;

  ViewVC Help
Powered by ViewVC 1.1.22