32 namespace RestFrames {
50 m_ChargeNum = std::abs(num);
51 m_ChargeDen = std::abs(den);
63 m_ChargeNum = std::abs(charge);
80 m_ChargeNum = std::abs(num);
81 m_ChargeDen = std::abs(den);
87 RFCharge::~RFCharge() {}
100 void RFCharge::Simplify(){
101 int f = gcd(m_ChargeNum, m_ChargeDen);
122 return (m_ChargeNum == val);
124 return (-m_ChargeNum == val);
141 return (m_ChargeNum != val);
143 return (-m_ChargeNum != val);
154 m_ChargeNum = std::abs(num);
164 m_ChargeNum = std::abs(val);
175 RFCharge RFCharge::operator+(
int val)
const {
179 RFCharge RFCharge::operator-(
const RFCharge& val)
const {
180 int den = val.GetDenominator();
186 RFCharge RFCharge::operator-(
int val)
const {
190 RFCharge RFCharge::operator*(
const RFCharge& val)
const {
192 val.GetDenominator()*m_ChargeDen);
195 RFCharge RFCharge::operator*(
int val)
const {
199 RFCharge RFCharge::operator/(
const RFCharge& val)
const {
201 val.GetNumerator()*m_ChargeDen);
204 RFCharge RFCharge::operator/(
int val)
const {
208 RFCharge& RFCharge::operator+=(
const RFCharge& val){
209 int den = val.GetDenominator();
210 int mnum =
GetNumerator()*den + val.GetNumerator()*m_ChargeDen;
217 m_ChargeNum = std::abs(mnum);
226 RFCharge& RFCharge::operator+=(
int val){
234 m_ChargeNum = std::abs(mnum);
242 RFCharge& RFCharge::operator-=(
const RFCharge& val){
243 int den = val.GetDenominator();
244 int mnum =
GetNumerator()*den - val.GetNumerator()*m_ChargeDen;
251 m_ChargeNum = std::abs(mnum);
260 RFCharge& RFCharge::operator-=(
int val){
268 m_ChargeNum = std::abs(mnum);
276 RFCharge& RFCharge::operator*=(
const RFCharge& val){
291 m_ChargeNum = std::abs(mnum);
292 m_ChargeDen *= val.GetDenominator();
300 RFCharge& RFCharge::operator*=(
int val){
315 m_ChargeNum = std::abs(mnum);
323 RFCharge& RFCharge::operator/=(
const RFCharge& val){
324 int num = val.GetNumerator();
336 m_ChargeDen *= std::abs(num);
337 m_ChargeNum *= val.GetDenominator();
345 RFCharge& RFCharge::operator/=(
int val){
356 m_ChargeDen *= std::abs(val);
364 RFCharge RFCharge::operator-() {
368 RFCharge::operator double()
const {
369 return double(GetNumerator())/
373 RFCharge operator*(
int val1,
const RFCharge& val2){
377 RFCharge operator/(
int val1,
const RFCharge& val2){
378 return RFCharge(val1)/val2;
381 int gcd(
int x,
int y){