Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayaankhan98 committed Oct 9, 2020
1 parent 0085952 commit f25e4d9
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 88 deletions.
33 changes: 20 additions & 13 deletions big-int/src/operators/greater_equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,25 @@

namespace libbig
{
//! Operator overload for >= for largeInt class
/*!
This operator returns a bool value which is
1 when the >= condition is satisfied between the two largeInt objects
0 otherwise
*/
bool largeInt::operator>=(const largeInt &a)
{
if(*this>a || *this==a) //! if both > and == conditions are satisfied then >= condition is satified too
/**
* @brief greater equal operator overload for largeInt class.
*
* @param right hand parameter of >= operator
* @return true if *this (object on which this function is
* called upon) is greater or equal else
* false
*
*/
bool largeInt::operator>=(const largeInt &a)
{
/**
* if both > and == conditions are satisfied then >= condition
* is satified too
*/
if(*this>a || *this==a)
{
return 1;
return true;
}
return 0;
}
} // namespace libbig
return false;
}
} // namespace libbig
88 changes: 57 additions & 31 deletions big-int/src/operators/greater_than.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,77 @@

namespace libbig
{
//! Operator overload for > for largeInt class
/*!
This operator returns a bool value which is
1 when the > condition is satisfied between the two largeInt objects
0 otherwise
*/
bool largeInt::operator>(const largeInt &a)
{
/** If first number is negative and second number is positive
* then > condition is not satisfied.
/**
* This operator returns a bool value which is
* 1 when the > condition is satisfied between the two largeInt object
* 0 otherwise
*/
bool largeInt::operator>(const largeInt &a)
{
/**
* If first number is negative and second number is positive
* then > condition is not satisfied.
*
*/
if(this->sign == NEGATIVE && a.sign == POSITIVE)
{
return 0;
return false;
}
/** If first number is positive and second number is negative
* then > condition is satisfied.

/**
* If first number is positive and second number is negative
* then > condition is satisfied.
*
*/
if(a.sign == NEGATIVE && this->sign == POSITIVE)
{
return 1;
return true;
}
/** If both the numbers have same sign
* then comparing their lengths

/**
* If both the numbers have same sign
* then comparing their lengths.
*
*/
if(this->number.length() > a.number.length())
{
return 0^this->sign; //! if first number is longer and both are negative then the condition is satisfied.
} //! but if first number is longer and both are positive then the condition is not satisfied.
/**
* if first number is longer and both are negative then
* the condition is satisfied, but if first number is
* longer and both are positive then the condition is not
* satisfied.
*/
return 0^this->sign;
}
if(this->number.length() < a.number.length())
{
return 1^this->sign; //! if first number is shorter and both are negative then the condition is not satisfied.
} //! but if first number is shorter and both are positive then the condition is satisfied.
/**
* if first number is shorter and both are negative then
* the condition is not satisfied, but if first number is
* shorter and both are positive then the condition is
* satisfied.
*
*/
return 1^this->sign;
}

for(int i=0;i<a.number.length();i++) //! if the length of both numbers are same then we compare each digit from LTR and the first non equal digit can determine whether the condition is satisfied
/**
* if the length of both numbers are same then we compare each
* digit from LTR and the first non equal digit can determine
* whether the condition is satisfied
*
*/
for(int i=0;i<a.number.length();i++)
{
if(this->number[i]>a.number[i])
{
return !(1^this->sign);
}
if(this->number[i]<a.number[i])
{
return !(0^this->sign);
}
if(this->number[i]>a.number[i])
{
return !(1^this->sign);
}
if(this->number[i]<a.number[i])
{
return !(0^this->sign);
}
}
return 0;
}
return false;
}
} // namespace libbig
31 changes: 18 additions & 13 deletions big-int/src/operators/less_equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,23 @@

namespace libbig
{
//! Operator overload for <= for largeInt class
/*!
This operator returns a bool value which is
1 when the <= condition is satisfied between the two largeInt objects
0 otherwise
*/
bool largeInt::operator<=(const largeInt &a)
{
if(*this<a || *this==a) //! if both < and == conditions are satisfied then <= condition is satified too
/**
* This operator returns a bool value which is
* 1 when the <= condition is satisfied between the two largeInt objects
* 0 otherwise
*
*/
bool largeInt::operator<=(const largeInt &a)
{
/**
* if both < and == conditions are satisfied then <= condition is
* satified too
*
*/
if(*this<a || *this==a)
{
return 1;
return true;
}
return 0;
}
} // namespace libbig
return false;
}
} // namespace libbig
88 changes: 57 additions & 31 deletions big-int/src/operators/less_than.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,77 @@

namespace libbig
{
//! Operator overload for < for largeInt class
/*!
This operator returns a bool value which is
1 when the < condition is satisfied between the two largeInt objects
0 otherwise
*/
bool largeInt::operator<(const largeInt &a)
{
/** If first number is negative and second number is positive
* then < condition is satisfied.
/**
* This operator returns a bool value which is
* 1 when the < condition is satisfied between the two largeInt objects
* 0 otherwise
*
*/
bool largeInt::operator<(const largeInt &a)
{
/**
* If first number is negative and second number is positive
* then < condition is satisfied.
*
*/
if(this->sign == NEGATIVE && a.sign == POSITIVE)
{
return 1;
return true;
}
/** If first number is positive and second number is negative
* then < condition is not satisfied.

/**
* If first number is positive and second number is negative
* then < condition is not satisfied.
*
*/
if(a.sign == NEGATIVE && this->sign == POSITIVE)
{
return 0;
return false;
}
/** If both the numbers have same sign
* then comparing their lengths

/**
* If both the numbers have same sign
* then comparing their lengths
*
*/
if(this->number.length() > a.number.length())
{
return 1^this->sign; //! if first number is longer and both are negative then the condition is not satisfied.
} //! but if first number is longer and both are positive then the condition is satisfied.
/**
* if first number is longer and both are negative then the
* condition is not satisfied, but if first number is longer
* and both are positive then the condition is satisfied.
*
*/
return 1^this->sign;
}
if(this->number.length() < a.number.length())
{
return 0^this->sign; //! if first number is shorter and both are negative then the condition is satisfied.
} //! but if first number is shorter and both are positive then the condition is not satisfied.
/**
* if first number is shorter and both are negative then the
* condition is satisfied, but if first number is shorter and
* both are positive then the condition is not satisfied.
*
*/
return 0^this->sign;
}

for(int i=0;i<a.number.length();i++) //! if the length of both numbers are same then we compare each digit from LTR and the first non equal digit can determine whether the condition is satisfied
/**
* if the length of both numbers are same then we compare each digit
* from LTR and the first non equal digit can determine whether the
* condition is satisfied
*
*/
for(int i=0;i<a.number.length();i++)
{
if(this->number[i]<a.number[i])
{
return !(1^this->sign);
}
if(this->number[i]>a.number[i])
{
return !(0^this->sign);
}
if(this->number[i]<a.number[i])
{
return !(1^this->sign);
}
if(this->number[i]>a.number[i])
{
return !(0^this->sign);
}
}
return 0;
}
return false;
}
} // namespace libbig

0 comments on commit f25e4d9

Please sign in to comment.