Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
968cadb8
Kaydet (Commit)
968cadb8
authored
Eki 17, 2014
tarafından
David Tardon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
allow construction of BigInt from sal_Int64 on 32 bit
Change-Id: Ib68920fc9bd693d2f2679b4fc27d9956dc42fc86
üst
08280034
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
145 additions
and
0 deletions
+145
-0
bigint.hxx
include/tools/bigint.hxx
+3
-0
CppunitTest_tools_test.mk
tools/CppunitTest_tools_test.mk
+1
-0
test_bigint.cxx
tools/qa/cppunit/test_bigint.cxx
+113
-0
bigint.cxx
tools/source/generic/bigint.cxx
+28
-0
No files found.
include/tools/bigint.hxx
Dosyayı görüntüle @
968cadb8
...
@@ -99,6 +99,9 @@ public:
...
@@ -99,6 +99,9 @@ public:
}
}
BigInt
(
sal_uInt32
nVal
);
BigInt
(
sal_uInt32
nVal
);
#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
BigInt
(
long
long
nVal
);
#endif
BigInt
(
const
BigInt
&
rBigInt
);
BigInt
(
const
BigInt
&
rBigInt
);
BigInt
(
const
OUString
&
rString
);
BigInt
(
const
OUString
&
rString
);
...
...
tools/CppunitTest_tools_test.mk
Dosyayı görüntüle @
968cadb8
...
@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,tools_test))
...
@@ -14,6 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,tools_test))
$(eval $(call gb_CppunitTest_use_external,tools_test,boost_headers))
$(eval $(call gb_CppunitTest_use_external,tools_test,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
$(eval $(call gb_CppunitTest_add_exception_objects,tools_test, \
tools/qa/cppunit/test_bigint \
tools/qa/cppunit/test_inetmime \
tools/qa/cppunit/test_inetmime \
tools/qa/cppunit/test_pathutils \
tools/qa/cppunit/test_pathutils \
tools/qa/cppunit/test_rational \
tools/qa/cppunit/test_rational \
...
...
tools/qa/cppunit/test_bigint.cxx
0 → 100644
Dosyayı görüntüle @
968cadb8
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <limits>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <rtl/math.hxx>
#include <tools/bigint.hxx>
namespace
tools
{
class
BigIntTest
:
public
CppUnit
::
TestFixture
{
public
:
#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
void
testConstructionFromInt64
();
#endif
CPPUNIT_TEST_SUITE
(
BigIntTest
);
#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
CPPUNIT_TEST
(
testConstructionFromLongLong
);
#endif
CPPUNIT_TEST_SUITE_END
();
};
#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
void
BigIntTest
::
testConstructionFromLongLong
()
{
// small positive number
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
42
));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
!
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
bi
.
IsLong
());
CPPUNIT_ASSERT_EQUAL
(
42L
,
bi
);
}
// small negative number
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
-
42
));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
bi
.
IsLong
());
CPPUNIT_ASSERT_EQUAL
(
-
42L
,
bi
);
}
// positive number just fitting to long
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
std
::
numeric_limits
<
long
>::
max
()));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
!
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
bi
.
IsLong
());
CPPUNIT_ASSERT_EQUAL
(
std
::
numeric_limits
<
long
>::
max
(),
bi
);
}
// negative number just fitting to long
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
std
::
numeric_limits
<
long
>::
min
()));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
bi
.
IsLong
());
CPPUNIT_ASSERT_EQUAL
(
std
::
numeric_limits
<
long
>::
min
(),
bi
);
}
// positive number not fitting to long
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
std
::
numeric_limits
<
long
>::
max
()
+
1
));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
!
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
!
bi
.
IsLong
());
}
// negative number not fitting to long
{
BigInt
bi
(
static_cast
<
sal_Int64
>
(
std
::
numeric_limits
<
long
>::
min
()
-
1
));
BigInt
bi
(
static_cast
<
sal_Int64
>
(
42
));
CPPUNIT_ASSERT
(
bi
.
IsSet
());
CPPUNIT_ASSERT
(
!
bi
.
IsZero
());
CPPUNIT_ASSERT
(
bi
.
IsNeg
());
CPPUNIT_ASSERT
(
!
bi
.
IsLong
());
}
}
#endif
CPPUNIT_TEST_SUITE_REGISTRATION
(
BigIntTest
);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools/source/generic/bigint.cxx
Dosyayı görüntüle @
968cadb8
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
*/
#include <limits>
#include <math.h>
#include <math.h>
#include <rtl/ustrbuf.hxx>
#include <rtl/ustrbuf.hxx>
...
@@ -577,6 +578,33 @@ BigInt::BigInt( sal_uInt32 nValue )
...
@@ -577,6 +578,33 @@ BigInt::BigInt( sal_uInt32 nValue )
}
}
}
}
#if SAL_TYPES_SIZEOFLONG < SAL_TYPES_SIZEOFLONGLONG
BigInt
::
BigInt
(
long
long
nValue
)
:
nVal
(
0
)
{
bIsSet
=
true
;
bIsNeg
=
nValue
<
0
;
nLen
=
0
;
unsigned
long
long
nUValue
=
static_cast
<
unsigned
long
long
>
(
bIsNeg
?
-
nValue
:
nValue
);
if
(
nUValue
>=
std
::
numeric_limits
<
long
>::
max
())
{
bIsBig
=
true
;
for
(
int
i
=
0
;
(
i
!=
sizeof
(
unsigned
long
long
)
/
2
)
&&
(
nUValue
!=
0
);
++
i
)
{
nNum
[
i
]
=
static_cast
<
sal_uInt16
>
(
nUValue
&
0xffffUL
);
nUValue
=
nUValue
>>
16
;
++
nLen
;
}
}
else
{
bIsBig
=
false
;
nVal
=
static_cast
<
long
>
(
nValue
);
}
}
#endif
BigInt
::
operator
sal_uIntPtr
()
const
BigInt
::
operator
sal_uIntPtr
()
const
{
{
if
(
!
bIsBig
)
if
(
!
bIsBig
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment