summaryrefslogtreecommitdiff
path: root/tools/source/generic/fract.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/generic/fract.cxx')
-rw-r--r--tools/source/generic/fract.cxx91
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx
index 020d894423ba..e9e2f5fec44f 100644
--- a/tools/source/generic/fract.cxx
+++ b/tools/source/generic/fract.cxx
@@ -191,6 +191,97 @@ void Fraction::ReduceInaccurate( unsigned nSignificantBits )
rational_ReduceInaccurate(value, nSignificantBits);
}
+Fraction::Fraction( const Fraction& rFrac )
+{
+ valid = rFrac.valid;
+ if ( valid )
+ value.assign( rFrac.value.numerator(), rFrac.value.denominator() );
+}
+
+long Fraction::GetNumerator() const
+{
+ if ( !valid ) {
+ SAL_WARN( "tools.fraction", "'GetNumerator()' on invalid fraction" );
+ return 0;
+ }
+ return value.numerator();
+}
+
+long Fraction::GetDenominator() const {
+ if ( !valid ) {
+ SAL_WARN( "tools.fraction", "'GetDenominator()' on invalid fraction" );
+ return -1;
+ }
+ return value.denominator();
+}
+
+Fraction& Fraction::operator=( const Fraction& rFrac )
+{
+ if ( this != &rFrac ) {
+ valid = rFrac.valid;
+ if ( valid )
+ value.assign( rFrac.value.numerator(), rFrac.value.denominator() );
+ }
+ return *this;
+}
+
+bool Fraction::IsValid() const
+{
+ return valid;
+}
+
+Fraction::operator long() const
+{
+ if ( !valid ) {
+ SAL_WARN( "tools.fraction", "'operator long()' on invalid fraction" );
+ return 0;
+ }
+ return boost::rational_cast<long>(value);
+}
+
+Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ Fraction aErg( rVal1 );
+ aErg += rVal2;
+ return aErg;
+}
+
+Fraction operator-( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ Fraction aErg( rVal1 );
+ aErg -= rVal2;
+ return aErg;
+}
+
+Fraction operator*( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ Fraction aErg( rVal1 );
+ aErg *= rVal2;
+ return aErg;
+}
+
+Fraction operator/( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ Fraction aErg( rVal1 );
+ aErg /= rVal2;
+ return aErg;
+}
+
+bool operator !=( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ return !(rVal1 == rVal2);
+}
+
+bool operator <=( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ return !(rVal1 > rVal2);
+}
+
+bool operator >=( const Fraction& rVal1, const Fraction& rVal2 )
+{
+ return !(rVal1 < rVal2);
+}
+
bool operator == ( const Fraction& rVal1, const Fraction& rVal2 )
{
if ( !rVal1.valid || !rVal2.valid ) {