OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fixedpnt.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// Borland Class Library
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Simple fixed point class that maintains numbers as 16.16
7/// Fixed by Bidus Yura to work with Micro$oft VC--.
8//----------------------------------------------------------------------------
9
10#if !defined(OWL_FIXEDPNT_H)
11#define OWL_FIXEDPNT_H
12
13#include <owl/private/defs.h>
14#if defined(BI_HAS_PRAGMA_ONCE)
15# pragma once
16#endif
17
18
19
20namespace owl {
21
22#include <owl/preclass.h>
23
24//
25/// \class TFixedPoint
26// ~~~~~ ~~~~~~~~~~~
28 public:
29 TFixedPoint(int s = 0) {Value = long(s) << 16;}
30 TFixedPoint(int num, int denom) {Value = long(num) * 65536L / denom;}
31
32 // Unary negation operator
33 //
34 TFixedPoint operator -() {return -Value;}
35
36 // Postfix increment/decrement operators
37 //
38 void operator ++(int) {Value += 1L << 16;}
39 void operator --(int) {Value -= 1L << 16;}
40
41 // Bitwise logical operators
42 //
43 TFixedPoint operator <<(unsigned n) {return long(Value << tchar(n));}
44 TFixedPoint operator >>(unsigned n) {return long(Value >> tchar(n));}
45
46 // Assignment operators
47 //
48 TFixedPoint& operator <<=(unsigned n) {Value <<= n; return *this;}
49 TFixedPoint& operator >>=(unsigned n) {Value >>= n; return *this;}
50
51 TFixedPoint& operator +=(const TFixedPoint& f) {Value += f.Value; return *this;}
52
53 TFixedPoint& operator -=(const TFixedPoint& f) {Value -= f.Value; return *this;}
54
55 TFixedPoint& operator *=(int s) {Value *= s; return *this;}
56 TFixedPoint& operator *=(const TFixedPoint& f) {Value = (Value >> 8) * (f.Value >> 8);
57 return *this;}
58
59 TFixedPoint& operator /=(int s) {Value /= s; return *this;}
60 TFixedPoint& operator /=(const TFixedPoint& f) {Value /= f.Value >> 8; Value <<= 8;
61 return *this;}
62
63 // Binary arithmetic operators
64 //
66 const TFixedPoint& r) {return l.Value + r.Value;}
68 const TFixedPoint& r) {return TFixedPoint(l) += r.Value;}
70 int r) {return r + l;}
71
73 const TFixedPoint& r) {return l.Value - r.Value;}
75 const TFixedPoint& r) {return TFixedPoint(l) -= r.Value;}
77 int r) {return l - TFixedPoint(r);}
78
80 const TFixedPoint& r) {return (l.Value >> 8) * (r.Value >> 8);}
82 const TFixedPoint& r) {return long(l * r.Value);}
84 int r) {return long(l.Value * r);}
85
87 const TFixedPoint& r) {return (l.Value /(r.Value >> 8)) << 8;}
89 const TFixedPoint& r) {return (long(l) << 16) / r.Value;}
91 int r) {return long(l.Value / r);}
92
93 // Equality operators
94 //
95 friend bool operator ==(const TFixedPoint& l,
96 const TFixedPoint& r) {return l.Value == r.Value;}
97 friend bool operator !=(const TFixedPoint& l,
98 const TFixedPoint& r) {return l.Value != r.Value;}
99 friend bool operator <(const TFixedPoint& l,
100 const TFixedPoint& r) {return l.Value < r.Value;}
101
102 // Conversion operator to int
103 //
104 operator int() {return int(Value >> 16);}
105
106 private:
107 TFixedPoint(long v) {Value = v;}
108
109 long Value;
110};
111
112
113#include <owl/posclass.h>
114
115} // OWL namespace
116
117
118#endif // CLASSLIB_FIXEDPNT_H
friend TFixedPoint operator/(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:86
TFixedPoint(int s=0)
Definition fixedpnt.h:29
TFixedPoint & operator-=(const TFixedPoint &f)
Definition fixedpnt.h:53
friend bool operator<(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:99
TFixedPoint(int num, int denom)
Definition fixedpnt.h:30
TFixedPoint & operator<<=(unsigned n)
Definition fixedpnt.h:48
friend TFixedPoint operator+(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:65
TFixedPoint operator<<(unsigned n)
Definition fixedpnt.h:43
friend bool operator==(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:95
void operator--(int)
Definition fixedpnt.h:39
friend bool operator!=(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:97
TFixedPoint operator>>(unsigned n)
Definition fixedpnt.h:44
TFixedPoint & operator*=(int s)
Definition fixedpnt.h:55
friend TFixedPoint operator*(const TFixedPoint &l, const TFixedPoint &r)
Definition fixedpnt.h:79
TFixedPoint & operator/=(int s)
Definition fixedpnt.h:59
void operator++(int)
Definition fixedpnt.h:38
TFixedPoint & operator>>=(unsigned n)
Definition fixedpnt.h:49
TFixedPoint & operator+=(const TFixedPoint &f)
Definition fixedpnt.h:51
TFixedPoint operator-()
Definition fixedpnt.h:34
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
char tchar
Definition defs.h:77