Skip to content

Commit 6af7115

Browse files
committed
Changes made for C++Builder compatibility
1 parent 9104931 commit 6af7115

5 files changed

+101
-11
lines changed

Source/Velthuis.BigDecimals.pas

+89
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,19 @@ BigDecimal = record
510510
/// <para>Only the low 8 bits of myUInt64 are copied to the byte.</para></remarks>
511511
class operator Explicit(const Value: BigDecimal): Int64;
512512

513+
// -- Conversion functions --
514+
515+
{$IFDEF HasExtended}
516+
function AsExtended: Extended;
517+
{$ENDIF}
518+
function AsDouble: Double;
519+
function AsSingle: Single;
520+
function AsBigInteger: BigInteger;
521+
function AsUInt64: UInt64;
522+
function AsInt64: Int64;
523+
function AsUInt32: UInt32;
524+
function AsInt32: Int32;
525+
513526

514527
// -- Mathematical functions --
515528

@@ -942,6 +955,82 @@ class procedure BigDecimal.AdjustForRoundingMode(var Quotient: BigInteger; const
942955
end;
943956
end;
944957

958+
{$IFDEF HasExtended}
959+
function BigDecimal.AsExtended: Extended;
960+
begin
961+
962+
end;
963+
{$ENDIF}
964+
965+
function BigDecimal.AsDouble: Double;
966+
begin
967+
Result := Double(Self);
968+
if IsInfinite(Result) then
969+
Error(ecConversion, ['BigDecimal', 'Double']);
970+
end;
971+
972+
function BigDecimal.AsSingle: Single;
973+
begin
974+
Result := Single(Self);
975+
if IsInfinite(Result) then
976+
Error(ecConversion, ['BigDecimal', 'Single']);
977+
end;
978+
979+
function BigDecimal.AsBigInteger: BigInteger;
980+
begin
981+
Result := BigInteger(Self);
982+
if Self.Scale > 0 then
983+
Error(ecRounding, []);
984+
end;
985+
986+
function BigDecimal.AsUInt64: UInt64;
987+
var
988+
D: BigDecimal;
989+
begin
990+
D := Self.RoundToScale(0, rmUnnecessary); // Throws if rounding necessary
991+
try
992+
Result := D.UnscaledValue.AsUInt64; // Throws if too big
993+
except
994+
Error(ecConversion, ['BigDecimal', 'UInt64']);
995+
end;
996+
end;
997+
998+
function BigDecimal.AsInt64: Int64;
999+
var
1000+
D: BigDecimal;
1001+
begin
1002+
D := Self.RoundToScale(0, rmUnnecessary);
1003+
try
1004+
Result := D.UnscaledValue.AsInt64;
1005+
finally
1006+
Error(ecConversion, ['BigDecimal', 'Int64']);
1007+
end;
1008+
end;
1009+
1010+
function BigDecimal.AsUInt32: UInt32;
1011+
var
1012+
D: BigDecimal;
1013+
begin
1014+
D := Self.RoundToScale(0, rmUnnecessary);
1015+
try
1016+
Result := D.UnscaledValue.AsCardinal;
1017+
finally
1018+
Error(ecConversion, ['BigDecimal', 'UInt32']);
1019+
end;
1020+
end;
1021+
1022+
function BigDecimal.AsInt32: Int32;
1023+
var
1024+
D: BigDecimal;
1025+
begin
1026+
D := Self.RoundToScale(0, rmUnnecessary);
1027+
try
1028+
Result := D.UnscaledValue.AsInteger;
1029+
finally
1030+
Error(ecConversion, ['BigDecimal', 'Int32']);
1031+
end;
1032+
end;
1033+
9451034
// Does a "binary search" to remove trailing zeros. This is much faster (10 times or more) than repeatedly
9461035
// dividing by BigInteger.Ten until there is a remainder, even for relatively small numbers of trailing zeros.
9471036
// Since this modifies Value, it cannot be made public, but there is a public version of this, called

Source/Velthuis.BigIntegers.operators.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef VB_OPERATORS
2-
#define VB_OPERATORS
1+
#ifndef VBI_OPERATORS
2+
#define VBI_OPERATORS
33

44
inline BigInteger operator +(const BigInteger& left, const BigInteger& right) { return BigInteger::Add(left, right); }
55
inline BigInteger operator -(const BigInteger& left, const BigInteger& right) { return BigInteger::Subtract(left, right); }

Source/Velthuis.BigIntegers.pas

+7-9
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ interface
205205
{$STACKFRAMES OFF}
206206
{$INLINE ON}
207207

208+
{$IF CompilerVersion >= CompilerVersionDelphiXE3}
209+
{$LEGACYIFEND ON}
210+
{$IFEND}
211+
208212
{$IF CompilerVersion >= CompilerVersionDelphiXE}
209213
{$CODEALIGN 16}
210214
{$ALIGN 16}
211215
{$IFEND}
212216

213-
{$IF CompilerVersion >= CompilerVersionDelphiXE3}
214-
{$LEGACYIFEND ON}
215-
{$IFEND}
216-
217217
{$IF CompilerVersion < CompilerVersionDelphiXE8}
218218
{$IF (DEFINED(WIN32) OR DEFINED(CPUX86)) AND NOT DEFINED(CPU32BITS)}
219219
{$DEFINE CPU32BITS}
@@ -232,11 +232,9 @@ interface
232232
{$IFEND}
233233

234234
// Assembler is only supplied for Windows targets. For other targets, PUREPASCAL must be defined.
235-
{$IFNDEF PUREPASCAL}
236-
{$IFNDEF MSWINDOWS}
237-
{$DEFINE PUREPASCAL}
238-
{$ENDIF}
239-
{$ENDIF}
235+
{$IF not defined(PUREPASCAL) and not defined(MSWINDOWS)}
236+
{$DEFINE PUREPASCAL}
237+
{$IFEND}
240238

241239
const
242240
{$IFDEF PUREPASCAL}

Tests/BigDecimals/BigDecimalDevelopmentTests.dproj

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
<DCCReference Include="..\..\Source\CompilerAndRTLVersions.pas"/>
114114
<None Include="BigDecimalTestData.inc"/>
115115
<None Include="..\..\Source\bases.inc"/>
116+
<None Include="..\..\Source\Velthuis.BigIntegers.operators.hpp"/>
117+
<None Include="..\..\Source\Velthuis.BigDecimals.operators.hpp"/>
116118
<BuildConfiguration Include="Release">
117119
<Key>Cfg_2</Key>
118120
<CfgParent>Base</CfgParent>

Tests/BigIntegers/BigIntegerDevelopmentTests.dproj

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<DCC_OutputXMLDocumentation>true</DCC_OutputXMLDocumentation>
113113
<DCC_UnitSearchPath>D:\Source\DropBox\Delphi\FastMM4-master;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
114114
<DCC_TypedAtParameter>true</DCC_TypedAtParameter>
115+
<DCC_AdditionalSwitches>--symbol-report</DCC_AdditionalSwitches>
115116
</PropertyGroup>
116117
<PropertyGroup Condition="'$(Cfg_2)'!=''">
117118
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>

0 commit comments

Comments
 (0)