summaryrefslogtreecommitdiff
path: root/include/tools/fract.hxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-09-26 12:49:50 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-09-27 09:05:55 +0200
commitcdd211d0a3f8bf977ecca67e72afbc63d53a72ee (patch)
treee0c5003ac5de84695efd86babfedb248af74df35 /include/tools/fract.hxx
parent467724410dc470ec259131f97abd836fe9b021a1 (diff)
check for NaN in Fraction
which can result from division by zero in earlier code, rather assert explicitly than suffer from weird very large sal_Int64 values (which is what NaN converts to, if we let it do the implicit conversion) Change-Id: Id059b84906bbc90a4fa51489ca96dc0267bb9342 Reviewed-on: https://gerrit.libreoffice.org/42798 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools/fract.hxx')
-rw-r--r--include/tools/fract.hxx9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx
index 68c0984a19a5..95aa5f5e727b 100644
--- a/include/tools/fract.hxx
+++ b/include/tools/fract.hxx
@@ -22,6 +22,7 @@
#include <sal/types.h>
#include <tools/toolsdllapi.h>
#include <memory>
+#include <type_traits>
class SvStream;
@@ -37,8 +38,14 @@ public:
Fraction();
Fraction( const Fraction & rFrac );
Fraction( Fraction && rFrac );
- Fraction( sal_Int64 nNum, sal_Int64 nDen );
explicit Fraction( double dVal );
+ Fraction( double nNum, double nDen );
+ Fraction( sal_Int64 nNum, sal_Int64 nDen );
+ // just to prevent ambiguity between the sal_Int64 and double constructors
+ template<typename T1, typename T2> Fraction(
+ T1 nNum, T2 nDen,
+ typename std::enable_if<std::is_integral<T1>::value && std::is_integral<T2>::value, int>::type = 0)
+ : Fraction( sal_Int64(nNum), sal_Int64(nDen) ) {}
~Fraction();
bool IsValid() const;