diff options
author | Juan Picca <jumapico@gmail.com> | 2014-11-04 00:18:02 -0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-11-12 12:24:02 +0000 |
commit | e52de1ca778d76a60579a656f61013b0dec1fdba (patch) | |
tree | 19db342d588fa632e5263e3efed290ef122a2956 /vcl/source | |
parent | a8af20dbbad18fd14b471ac52baef2015c89d242 (diff) |
Fraction: rewrite condition 'GetDenominator()==-1'
Change-Id: I483024fd0ef3e4e187a143631b2e8bd953fa3a52
Reviewed-on: https://gerrit.libreoffice.org/12240
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/outdev/map.cxx | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index fa79b77c3e39..b9bd53205862 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -45,6 +45,12 @@ ctor fraction once); we could also do this with BigInts static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 ) { + if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless + { + DBG_ASSERT(false,"Invalid parameter for ImplMakeFraction"); + return Fraction( 1, 1 ); + } + long i = 1; if ( nN1 < 0 ) { i = -i; nN1 = -nN1; } @@ -53,17 +59,9 @@ static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 ) if ( nD2 < 0 ) { i = -i; nD2 = -nD2; } // all positive; i sign - Fraction aF( i*nN1, nD1 ); - aF *= Fraction( nN2, nD2 ); + Fraction aF = Fraction( i*nN1, nD1 ) * Fraction( nN2, nD2 ); - if( nD1 == 0 || nD2 == 0 ) //under these bad circumstances the following while loop will be endless - { - DBG_ASSERT(false,"Invalid parameter for ImplMakeFraction"); - return Fraction( 1, 1 ); - } - - while ( aF.GetDenominator() == -1 ) - { + while ( !aF.IsValid() ) { if ( nN1 > nN2 ) nN1 = (nN1 + 1) / 2; else @@ -73,8 +71,7 @@ static Fraction ImplMakeFraction( long nN1, long nN2, long nD1, long nD2 ) else nD2 = (nD2 + 1) / 2; - aF = Fraction( i*nN1, nD1 ); - aF *= Fraction( nN2, nD2 ); + aF = Fraction( i*nN1, nD1 ) * Fraction( nN2, nD2 ); } return aF; |