OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
Loading...
Searching...
No Matches
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
20
namespace
owl
{
21
22
#include <
owl/preclass.h
>
23
24
//
25
/// \class TFixedPoint
26
// ~~~~~ ~~~~~~~~~~~
27
class
TFixedPoint
{
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
//
65
friend
TFixedPoint
operator +
(
const
TFixedPoint
& l,
66
const
TFixedPoint
& r) {
return
l.Value + r.Value;}
67
friend
TFixedPoint
operator +
(
int
l,
68
const
TFixedPoint
& r) {
return
TFixedPoint
(l) += r.Value;}
69
friend
TFixedPoint
operator +
(
const
TFixedPoint
& l,
70
int
r) {
return
r + l;}
71
72
friend
TFixedPoint
operator -
(
const
TFixedPoint
& l,
73
const
TFixedPoint
& r) {
return
l.Value - r.Value;}
74
friend
TFixedPoint
operator -
(
int
l,
75
const
TFixedPoint
& r) {
return
TFixedPoint
(l) -= r.Value;}
76
friend
TFixedPoint
operator -
(
const
TFixedPoint
& l,
77
int
r) {
return
l -
TFixedPoint
(r);}
78
79
friend
TFixedPoint
operator *
(
const
TFixedPoint
& l,
80
const
TFixedPoint
& r) {
return
(l.Value >> 8) * (r.Value >> 8);}
81
friend
TFixedPoint
operator *
(
int
l,
82
const
TFixedPoint
& r) {
return
long(l * r.Value);}
83
friend
TFixedPoint
operator *
(
const
TFixedPoint
& l,
84
int
r) {
return
long(l.Value * r);}
85
86
friend
TFixedPoint
operator /
(
const
TFixedPoint
& l,
87
const
TFixedPoint
& r) {
return
(l.Value /(r.Value >> 8)) << 8;}
88
friend
TFixedPoint
operator /
(
int
l,
89
const
TFixedPoint
& r) {
return
(
long
(l) << 16) / r.Value;}
90
friend
TFixedPoint
operator /
(
const
TFixedPoint
& l,
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
owl::TFixedPoint::operator/
friend TFixedPoint operator/(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:86
owl::TFixedPoint::TFixedPoint
TFixedPoint(int s=0)
Definition
fixedpnt.h:29
owl::TFixedPoint::operator-=
TFixedPoint & operator-=(const TFixedPoint &f)
Definition
fixedpnt.h:53
owl::TFixedPoint::operator<
friend bool operator<(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:99
owl::TFixedPoint::TFixedPoint
TFixedPoint(int num, int denom)
Definition
fixedpnt.h:30
owl::TFixedPoint::operator<<=
TFixedPoint & operator<<=(unsigned n)
Definition
fixedpnt.h:48
owl::TFixedPoint::operator+
friend TFixedPoint operator+(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:65
owl::TFixedPoint::operator<<
TFixedPoint operator<<(unsigned n)
Definition
fixedpnt.h:43
owl::TFixedPoint::operator==
friend bool operator==(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:95
owl::TFixedPoint::operator--
void operator--(int)
Definition
fixedpnt.h:39
owl::TFixedPoint::operator!=
friend bool operator!=(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:97
owl::TFixedPoint::operator>>
TFixedPoint operator>>(unsigned n)
Definition
fixedpnt.h:44
owl::TFixedPoint::operator*=
TFixedPoint & operator*=(int s)
Definition
fixedpnt.h:55
owl::TFixedPoint::operator*
friend TFixedPoint operator*(const TFixedPoint &l, const TFixedPoint &r)
Definition
fixedpnt.h:79
owl::TFixedPoint::operator/=
TFixedPoint & operator/=(int s)
Definition
fixedpnt.h:59
owl::TFixedPoint::operator++
void operator++(int)
Definition
fixedpnt.h:38
owl::TFixedPoint::operator>>=
TFixedPoint & operator>>=(unsigned n)
Definition
fixedpnt.h:49
owl::TFixedPoint::operator+=
TFixedPoint & operator+=(const TFixedPoint &f)
Definition
fixedpnt.h:51
owl::TFixedPoint::operator-
TFixedPoint operator-()
Definition
fixedpnt.h:34
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::tchar
char tchar
Definition
defs.h:77
defs.h
posclass.h
preclass.h
include
owl
fixedpnt.h
Generated by
1.18.0