Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
yh2920
Fixed-point
Commits
4e869619
Commit
4e869619
authored
Jul 15, 2021
by
yh2920
Browse files
operator overload with float
parent
5ee0fe4f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Fixed-point.cpp
View file @
4e869619
...
...
@@ -85,18 +85,18 @@ public:
FixedPoint
&
operator
+=
(
int
i
)
{
FixedPoint
x
=
*
this
;
x
+=
F
pF
(
i
);
x
+=
F
ixedPoint
(
i
);
return
x
;
}
FixedPoint
&
operator
-=
(
int
i
)
{
FixedPoint
x
=
*
this
;
x
-=
F
pF
(
i
);
x
-=
F
ixedPoint
(
i
);
return
x
;
}
FixedPoint
&
operator
*=
(
int
i
)
{
value
*=
r
;
value
*=
i
;
return
*
this
;
}
...
...
@@ -109,13 +109,13 @@ public:
FixedPoint
operator
-
(
int
i
)
const
{
FixedPoint
x
=
*
this
;
x
-=
r
;
x
-=
i
;
return
x
;
}
FixedPoint
operator
*
(
int
i
)
const
{
FixedPoint
x
=
*
this
;
x
*=
r
;
x
*=
i
;
return
x
;
}
//Binary Operator Overloads
...
...
@@ -124,7 +124,7 @@ public:
}
bool
operator
!=
(
int
i
)
const
{
return
!
(
*
this
==
r
);
return
!
(
*
this
==
i
);
}
bool
operator
<
(
int
i
)
const
{
...
...
@@ -144,7 +144,69 @@ public:
return
value
>=
(
int
)
i
<<
numFracBits
;
}
//operator overload with float
FixedPoint
&
operator
+=
(
float
f
)
{
FixedPoint
x
=
*
this
;
x
+=
FixedPoint
(
f
);
return
x
;
}
FixedPoint
&
operator
-=
(
float
f
)
{
FixedPoint
x
=
*
this
;
x
-=
FixedPoint
(
f
);
return
x
;
}
FixedPoint
&
operator
*=
(
float
f
)
{
FixedPoint
x
=
*
this
;
x
*=
FixedPoint
(
f
);
return
*
this
;
}
FixedPoint
operator
+
(
float
f
)
const
{
FixedPoint
x
=
*
this
;
x
+=
f
;
return
x
;
}
FixedPoint
operator
-
(
float
f
)
const
{
FixedPoint
x
=
*
this
;
x
-=
f
;
return
x
;
}
FixedPoint
operator
*
(
float
f
)
const
{
FixedPoint
x
=
*
this
;
x
*=
f
;
return
x
;
}
//Binary Operator Overloads
bool
operator
==
(
float
f
)
const
{
return
*
this
==
FixedPoint
(
f
);
}
bool
operator
!=
(
float
f
)
const
{
return
!
(
*
this
==
f
);
}
bool
operator
<
(
float
f
)
const
{
return
*
this
<
FixedPoint
(
f
);
}
bool
operator
>
(
float
f
)
const
{
return
*
this
>
FixedPoint
(
f
);
}
bool
operator
<=
(
float
f
)
const
{
return
*
this
<=
FixedPoint
(
f
);
}
bool
operator
>=
(
float
f
)
const
{
return
*
this
>=
FixedPoint
(
f
);
}
int
ToInt
()
const
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment