1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_TOOLS_FRACT_HXX
20 #define INCLUDED_TOOLS_FRACT_HXX
22 #include <sal/types.h>
23 #include <tools/toolsdllapi.h>
28 // This class uses the platform defined type 'long' as valid values but do all
29 // calculations using sal_Int64 with checks for 'long' overflows.
30 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Fraction
34 std::unique_ptr
<Impl
> mpImpl
;
36 bool HasOverflowValue();
40 Fraction( const Fraction
& rFrac
);
41 Fraction( Fraction
&& rFrac
);
42 Fraction( long nNum
, long nDen
);
43 Fraction( double dVal
);
48 long GetNumerator() const;
49 long GetDenominator() const;
51 operator long() const;
52 operator double() const;
54 Fraction
& operator=( const Fraction
& rfrFrac
);
55 Fraction
& operator=( Fraction
&& rfrFrac
);
57 Fraction
& operator+=( const Fraction
& rfrFrac
);
58 Fraction
& operator-=( const Fraction
& rfrFrac
);
59 Fraction
& operator*=( const Fraction
& rfrFrac
);
60 Fraction
& operator/=( const Fraction
& rfrFrac
);
62 void ReduceInaccurate( unsigned nSignificantBits
);
64 TOOLS_DLLPUBLIC
friend Fraction
operator+( const Fraction
& rVal1
, const Fraction
& rVal2
);
65 TOOLS_DLLPUBLIC
friend Fraction
operator-( const Fraction
& rVal1
, const Fraction
& rVal2
);
66 TOOLS_DLLPUBLIC
friend Fraction
operator*( const Fraction
& rVal1
, const Fraction
& rVal2
);
67 TOOLS_DLLPUBLIC
friend Fraction
operator/( const Fraction
& rVal1
, const Fraction
& rVal2
);
69 TOOLS_DLLPUBLIC
friend bool operator==( const Fraction
& rVal1
, const Fraction
& rVal2
);
70 TOOLS_DLLPUBLIC
friend bool operator!=( const Fraction
& rVal1
, const Fraction
& rVal2
);
71 TOOLS_DLLPUBLIC
friend bool operator< ( const Fraction
& rVal1
, const Fraction
& rVal2
);
72 TOOLS_DLLPUBLIC
friend bool operator> ( const Fraction
& rVal1
, const Fraction
& rVal2
);
73 TOOLS_DLLPUBLIC
friend bool operator<=( const Fraction
& rVal1
, const Fraction
& rVal2
);
74 TOOLS_DLLPUBLIC
friend bool operator>=( const Fraction
& rVal1
, const Fraction
& rVal2
);
76 TOOLS_DLLPUBLIC
friend SvStream
& ReadFraction( SvStream
& rIStream
, Fraction
const & rFract
);
77 TOOLS_DLLPUBLIC
friend SvStream
& WriteFraction( SvStream
& rOStream
, const Fraction
& rFract
);
80 TOOLS_DLLPUBLIC Fraction
operator+( const Fraction
& rVal1
, const Fraction
& rVal2
);
81 TOOLS_DLLPUBLIC Fraction
operator-( const Fraction
& rVal1
, const Fraction
& rVal2
);
82 TOOLS_DLLPUBLIC Fraction
operator*( const Fraction
& rVal1
, const Fraction
& rVal2
);
83 TOOLS_DLLPUBLIC Fraction
operator/( const Fraction
& rVal1
, const Fraction
& rVal2
);
84 TOOLS_DLLPUBLIC
bool operator !=( const Fraction
& rVal1
, const Fraction
& rVal2
);
85 TOOLS_DLLPUBLIC
bool operator <=( const Fraction
& rVal1
, const Fraction
& rVal2
);
86 TOOLS_DLLPUBLIC
bool operator >=( const Fraction
& rVal1
, const Fraction
& rVal2
);
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */