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 .
23 #include <rtl/ustring.hxx>
24 #include "tools/toolsdllapi.h"
25 #include <tools/solar.h>
29 #ifdef _TLBIGINT_INT64
38 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED BigInt
42 unsigned short nNum
[MAX_DIGITS
];
43 sal_uInt8 nLen
: 5; // current length
44 sal_Bool bIsNeg
: 1, // Is Sign negative?
45 bIsBig
: 1, // sal_True == BigInt
46 bIsSet
: 1; // Not "Null" (not "not 0")
48 TOOLS_DLLPRIVATE
void MakeBigInt(BigInt
const &);
49 TOOLS_DLLPRIVATE
void Normalize();
50 TOOLS_DLLPRIVATE
void Mult(BigInt
const &, sal_uInt16
);
51 TOOLS_DLLPRIVATE
void Div(sal_uInt16
, sal_uInt16
&);
52 TOOLS_DLLPRIVATE sal_Bool
IsLess(BigInt
const &) const;
53 TOOLS_DLLPRIVATE
void AddLong(BigInt
&, BigInt
&);
54 TOOLS_DLLPRIVATE
void SubLong(BigInt
&, BigInt
&);
55 TOOLS_DLLPRIVATE
void MultLong(BigInt
const &, BigInt
&) const;
56 TOOLS_DLLPRIVATE
void DivLong(BigInt
const &, BigInt
&) const;
57 TOOLS_DLLPRIVATE
void ModLong(BigInt
const &, BigInt
&) const;
58 TOOLS_DLLPRIVATE sal_Bool
ABS_IsLess(BigInt
const &) const;
65 BigInt( double nVal
);
66 BigInt( sal_uInt16 nVal
);
67 BigInt( sal_uInt32 nVal
);
68 BigInt( const BigInt
& rBigInt
);
69 BigInt( const OUString
& rString
);
70 #ifdef _TLBIGINT_INT64
71 BigInt( const SbxINT64
&r
);
72 BigInt( const SbxUINT64
&r
);
75 operator short() const;
76 operator long() const;
78 operator double() const;
79 operator sal_uInt16() const;
80 operator sal_uIntPtr() const;
82 void Set( sal_Bool bSet
) { bIsSet
= bSet
; }
83 OUString
GetString() const;
85 sal_Bool
IsSet() const { return bIsSet
; }
86 sal_Bool
IsNeg() const;
87 sal_Bool
IsZero() const;
88 sal_Bool
IsOne() const;
89 sal_Bool
IsLong() const { return !bIsBig
; }
91 #ifdef _TLBIGINT_INT64
92 sal_Bool
INT64 ( SbxINT64
*p
) const;
93 sal_Bool
UINT64( SbxUINT64
*p
) const;
96 BigInt
& operator =( const BigInt
& rVal
);
97 BigInt
& operator +=( const BigInt
& rVal
);
98 BigInt
& operator -=( const BigInt
& rVal
);
99 BigInt
& operator *=( const BigInt
& rVal
);
100 BigInt
& operator /=( const BigInt
& rVal
);
101 BigInt
& operator %=( const BigInt
& rVal
);
103 BigInt
& operator =( const short nValue
);
104 BigInt
& operator =( const long nValue
);
105 BigInt
& operator =( const int nValue
);
106 BigInt
& operator =( const sal_uInt16 nValue
);
108 friend inline BigInt
operator +( const BigInt
& rVal1
, const BigInt
& rVal2
);
109 friend inline BigInt
operator -( const BigInt
& rVal1
, const BigInt
& rVal2
);
110 friend inline BigInt
operator *( const BigInt
& rVal1
, const BigInt
& rVal2
);
111 friend inline BigInt
operator /( const BigInt
& rVal1
, const BigInt
& rVal2
);
112 friend inline BigInt
operator %( const BigInt
& rVal1
, const BigInt
& rVal2
);
114 TOOLS_DLLPUBLIC
friend sal_Bool
operator==( const BigInt
& rVal1
, const BigInt
& rVal2
);
115 friend inline sal_Bool
operator!=( const BigInt
& rVal1
, const BigInt
& rVal2
);
116 TOOLS_DLLPUBLIC
friend sal_Bool
operator< ( const BigInt
& rVal1
, const BigInt
& rVal2
);
117 TOOLS_DLLPUBLIC
friend sal_Bool
operator> ( const BigInt
& rVal1
, const BigInt
& rVal2
);
118 friend inline sal_Bool
operator<=( const BigInt
& rVal1
, const BigInt
& rVal2
);
119 friend inline sal_Bool
operator>=( const BigInt
& rVal1
, const BigInt
& rVal2
);
121 friend class Fraction
;
124 inline BigInt::BigInt()
131 inline BigInt::BigInt( short nValue
)
138 inline BigInt::BigInt( long nValue
)
145 inline BigInt::BigInt( int nValue
)
152 inline BigInt::BigInt( sal_uInt16 nValue
)
159 inline BigInt::operator short() const
161 if ( !bIsBig
&& nVal
>= SHRT_MIN
&& nVal
<= SHRT_MAX
)
167 inline BigInt::operator long() const
175 inline BigInt::operator int() const
177 if ( !bIsBig
&& (nVal
== (long)(int)nVal
) )
183 inline BigInt::operator sal_uInt16() const
185 if ( !bIsBig
&& nVal
>= 0 && nVal
<= USHRT_MAX
)
186 return (sal_uInt16
)nVal
;
191 inline BigInt
& BigInt::operator =( const short nValue
)
200 inline BigInt
& BigInt::operator =( const long nValue
)
209 inline BigInt
& BigInt::operator =( const int nValue
)
218 inline BigInt
& BigInt::operator =( const sal_uInt16 nValue
)
227 inline sal_Bool
BigInt::IsNeg() const
232 return (sal_Bool
)bIsNeg
;
235 inline sal_Bool
BigInt::IsZero() const
243 inline sal_Bool
BigInt::IsOne() const
251 inline void BigInt::Abs()
259 inline BigInt
operator+( const BigInt
&rVal1
, const BigInt
&rVal2
)
261 BigInt
aErg( rVal1
);
266 inline BigInt
operator-( const BigInt
&rVal1
, const BigInt
&rVal2
)
268 BigInt
aErg( rVal1
);
273 inline BigInt
operator*( const BigInt
&rVal1
, const BigInt
&rVal2
)
275 BigInt
aErg( rVal1
);
280 inline BigInt
operator/( const BigInt
&rVal1
, const BigInt
&rVal2
)
282 BigInt
aErg( rVal1
);
287 inline BigInt
operator%( const BigInt
&rVal1
, const BigInt
&rVal2
)
289 BigInt
aErg( rVal1
);
294 inline sal_Bool
operator!=( const BigInt
& rVal1
, const BigInt
& rVal2
)
296 return !(rVal1
== rVal2
);
299 inline sal_Bool
operator<=( const BigInt
& rVal1
, const BigInt
& rVal2
)
301 return !( rVal1
> rVal2
);
304 inline sal_Bool
operator>=( const BigInt
& rVal1
, const BigInt
& rVal2
)
306 return !(rVal1
< rVal2
);
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */