Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update bootstrap compiler to build as far as the proto compiler

Update bootstrap compiler using a modified F# 2.0 compiler which traps
a harmless error about XMLDocs and prints it to the screen. This allows
the F# 3.0 build to proceed as far as building the proto compiler.

The finalized F# 3.0 FSharp.Core does not yet build.
  • Loading branch information...
commit 107f1d90762a62099c349583583b654b652e2b8e 1 parent 1afbef6
@funnelweb funnelweb authored
Showing with 651 additions and 461 deletions.
  1. BIN  lib/bootstrap/2.0/FSharp.Build.dll
  2. BIN  lib/bootstrap/2.0/FSharp.Compiler.Interactive.Settings.dll
  3. BIN  lib/bootstrap/2.0/FSharp.Compiler.Server.Shared.dll
  4. BIN  lib/bootstrap/2.0/FSharp.Compiler.dll
  5. BIN  lib/bootstrap/2.0/FSharp.Core.dll
  6. BIN  lib/bootstrap/2.0/FSharp.Core.optdata
  7. BIN  lib/bootstrap/2.0/FSharp.Core.sigdata
  8. +194 −0 lib/bootstrap/2.0/Microsoft.FSharp.targets
  9. BIN  lib/bootstrap/2.0/fsc.exe
  10. BIN  lib/bootstrap/2.0/fsi.exe
  11. BIN  lib/bootstrap/4.0/FSharp.Build.dll
  12. BIN  lib/bootstrap/4.0/FSharp.Compiler.Interactive.Settings.dll
  13. BIN  lib/bootstrap/4.0/FSharp.Compiler.Server.Shared.dll
  14. BIN  lib/bootstrap/4.0/FSharp.Compiler.dll
  15. BIN  lib/bootstrap/4.0/FSharp.Core.dll
  16. BIN  lib/bootstrap/4.0/FSharp.Core.optdata
  17. BIN  lib/bootstrap/4.0/FSharp.Core.sigdata
  18. +1 −1  lib/bootstrap/4.0/Microsoft.FSharp.targets
  19. BIN  lib/bootstrap/4.0/fsc.exe
  20. BIN  lib/bootstrap/4.0/fsi.exe
  21. +24 −36 src/fsharp/FSharp.Core/FSharp.Core.fsproj
  22. +19 −4 src/fsharp/FSharp.Core/Makefile.in
  23. +413 −409 src/fsharp/FSharp.Core/math/z.fs
  24. +0 −11 src/fsharp/Fsc-proto/Makefile.in
View
BIN  lib/bootstrap/2.0/FSharp.Build.dll 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Compiler.Interactive.Settings.dll
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Compiler.Server.Shared.dll
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Compiler.dll 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Core.dll
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Core.optdata
Binary file not shown
View
BIN  lib/bootstrap/2.0/FSharp.Core.sigdata
Binary file not shown
View
194 lib/bootstrap/2.0/Microsoft.FSharp.targets
@@ -0,0 +1,194 @@
+<!--
+***********************************************************************************************
+Microsoft.FSharp.targets
+
+WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
+ created a backup copy. Incorrect changes to this file will make it
+ impossible to load or build your projects from the command-line or the IDE.
+
+This file defines the steps in the standard build process specific for F# .NET projects.
+For example, it contains the step that actually calls the F# compiler. The remainder
+of the build process is defined in Microsoft.Common.targets, which is imported by
+this file.
+
+Copyright (C) Microsoft Corporation. All rights reserved.
+***********************************************************************************************
+-->
+
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+ <UsingTask TaskName="Fsc" AssemblyFile="FSharp.Build.dll"/>
+ <UsingTask TaskName="CreateFSharpManifestResourceName" AssemblyFile="FSharp.Build.dll"/>
+
+
+ <PropertyGroup>
+ <!-- FSharpTargetsDir is the directory where the targets file lives -->
+ <FSharpTargetsDir Condition="'$(FSharpTargetsDir)'==''">$(MSBuildExtensionsPath32)\FSharp\1.0\</FSharpTargetsDir>
+ <!-- FSharpTargetsFullPath is the full path (dir + filename) of the targets file -->
+ <FSharpTargetsFullPath Condition="'$(FSharpTargetsDir)'!=''">$(FSharpTargetsDir)\Microsoft.FSharp.targets</FSharpTargetsFullPath>
+ <MSBuildAllProjects>$(MSBuildAllProjects);$(FSharpTargetsFullPath)</MSBuildAllProjects>
+ <DefaultLanguageSourceExtension>.fs</DefaultLanguageSourceExtension>
+ <Language>F#</Language>
+ <Tailcalls Condition="'$(Tailcalls)'==''">$(Optimize)</Tailcalls>
+ <!-- Visual studio requires a non-empty RootNamespace value for "Add New Item" to work. -->
+ <RootNamespace Condition="'$(RootNamespace)'==''">RootNamespace</RootNamespace>
+ </PropertyGroup>
+
+ <!--
+ The CreateManifestResourceNames target create the manifest resource names from the .RESX
+ files.
+
+ [IN]
+ @(EmbeddedResource) - The list of EmbeddedResource items that have been pre-processed to add metadata about resource type
+ Expected Metadata "Type" can either be "Resx" or "Non-Resx"
+
+ [OUT]
+ @(EmbeddedResource) - EmbeddedResource items with metadata
+
+ For F# applications the transformation is like:
+
+ Resources1.resx => Resources1 => Build into main assembly
+ SubFolder\Resources1.resx => SubFolder.Resources1 => Build into main assembly
+ Resources1.fr.resx => Resources1.fr => Build into satellite assembly
+ Resources1.notaculture.resx => Resources1.notaculture => Build into main assembly
+
+ For other project systems, this transformation may be different.
+ -->
+ <PropertyGroup>
+ <CreateManifestResourceNamesDependsOn></CreateManifestResourceNamesDependsOn>
+ </PropertyGroup>
+ <Target
+ Name="CreateManifestResourceNames"
+ Condition="'@(EmbeddedResource)' != ''"
+ DependsOnTargets="$(CreateManifestResourceNamesDependsOn)"
+ >
+
+ <ItemGroup>
+ <_Temporary Remove="@(_Temporary)" />
+ </ItemGroup>
+
+ <!-- Create manifest names for culture and non-culture Resx files, and for non-culture Non-Resx resources -->
+ <CreateFSharpManifestResourceName
+ ResourceFiles="@(EmbeddedResource)"
+ RootNamespace="$(RootNamespace)"
+ Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and ('%(EmbeddedResource.WithCulture)' == 'false' or '%(EmbeddedResource.Type)' == 'Resx')">
+
+ <Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="_Temporary" />
+
+ </CreateFSharpManifestResourceName>
+
+ <!-- Create manifest names for all culture non-resx resources -->
+ <CreateFSharpManifestResourceName
+ ResourceFiles="@(EmbeddedResource)"
+ RootNamespace="$(RootNamespace)"
+ PrependCultureAsDirectory="false"
+ Condition="'%(EmbeddedResource.ManifestResourceName)' == '' and '%(EmbeddedResource.WithCulture)' == 'true' and '%(EmbeddedResource.Type)' == 'Non-Resx'">
+
+ <Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="_Temporary" />
+
+ </CreateFSharpManifestResourceName>
+
+ <ItemGroup>
+ <EmbeddedResource Remove="@(EmbeddedResource)" Condition="'%(EmbeddedResource.ManifestResourceName)' == ''"/>
+ <EmbeddedResource Include="@(_Temporary)" />
+ <_Temporary Remove="@(_Temporary)" />
+ </ItemGroup>
+ </Target>
+
+ <ItemGroup>
+ <DocFileItem Include="$(DocumentationFile)" Condition="'$(DocumentationFile)'!=''"/>
+ </ItemGroup>
+
+ <ItemGroup Condition="'$(_DebugSymbolsProduced)' == 'true' and '$(PdbFile)' != ''">
+ <_DebugSymbolsIntermediatePathTemporary Include="$(PdbFile)"/>
+ <!-- Add any missing .pdb extension, as the compiler does -->
+ <_DebugSymbolsIntermediatePath Include="@(_DebugSymbolsIntermediatePathTemporary->'%(RootDir)%(Directory)%(Filename).pdb')"/>
+ </ItemGroup>
+
+ <PropertyGroup>
+ <CoreCompileDependsOn>_ComputeNonExistentFileProperty</CoreCompileDependsOn>
+ </PropertyGroup>
+
+ <Target
+ Name="CoreCompile"
+ Inputs="$(MSBuildAllProjects);
+ @(CompileBefore);
+ @(Compile);
+ @(CompileAfter);
+ @(_CoreCompileResourceInputs);
+ $(ApplicationIcon);
+ $(AssemblyOriginatorKeyFile);
+ @(ReferencePath);
+ @(CompiledLicenseFile);
+ @(EmbeddedDocumentation);
+ $(Win32Resource);
+ $(Win32Manifest);
+ @(CustomAdditionalCompileInputs);
+ $(VersionFile);
+ $(KeyOriginatorFile)"
+ Outputs="@(DocFileItem);
+ @(IntermediateAssembly);
+ @(_DebugSymbolsIntermediatePath);
+ $(NonExistentFile);
+ @(CustomAdditionalCompileOutputs)"
+ DependsOnTargets="$(CoreCompileDependsOn)"
+ >
+
+ <!-- See bug 6053
+ <Error
+ Condition="'$(SilverlightVersion)' != '' and !(Exists('$(ProgramFiles)\Microsoft F#\Silverlight\Libraries\Client\$(SilverlightVersion)\FSharp.Core.dll'))"
+ Text="F# runtime for Silverlight version $(SilverlightVersion) is not installed. Please go to http://go.microsoft.com/fwlink/?LinkId=177463 to download and install matching F# runtime"
+ />
+ -->
+
+ <Warning
+ Condition="'$(Win32ResourceFile)' != '' "
+ Text="The property &lt;Win32ResourceFile> has been renamed to &lt;Win32Resource>. Update your project file to ensure that the correct value is passed via the --win32res option to the F# compiler."
+ />
+
+ <!-- Condition is to filter out the _CoreCompileResourceInputs so that it doesn't pass in culture resources to the compiler -->
+ <Fsc Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
+ BaseAddress="$(BaseAddress)"
+ CodePage="$(CodePage)"
+ DebugSymbols="$(DebugSymbols)"
+ DebugType="$(DebugType)"
+ DefineConstants="$(DefineConstants)"
+ DisabledWarnings="$(NoWarn)"
+ DocumentationFile="$(DocumentationFile)"
+ GenerateInterfaceFile="$(GenerateInterfaceFile)"
+ KeyFile="$(KeyOriginatorFile)"
+ LCID="$(LCID)"
+ NoFramework="true"
+ Optimize="$(Optimize)"
+ OtherFlags="$(OtherFlags)"
+ OutputAssembly="@(IntermediateAssembly)"
+ PdbFile="$(PdbFile)"
+ Platform="$(PlatformTarget)"
+ References="@(ReferencePath)"
+ ReferencePath="$(ReferencePath)"
+ Resources="@(_CoreCompileResourceInputs);@(CompiledLicenseFile);@(AdditionalEmbeddedResource)"
+ Sources="@(CompileBefore);@(Compile);@(CompileAfter)"
+ Tailcalls="$(Tailcalls)"
+ TargetType="$(OutputType)"
+ ToolExe="$(FscToolExe)"
+ ToolPath="$(FscToolPath)"
+ TreatWarningsAsErrors="$(TreatWarningsAsErrors)"
+ Utf8Output="$(Utf8Output)"
+ VersionFile="$(VersionFile)"
+ VisualStudioStyleErrors="$(VisualStudioStyleErrors)"
+ WarningLevel="$(WarningLevel)"
+ WarningsAsErrors="$(WarningsAsErrors)"
+ Win32ManifestFile="$(Win32Manifest)"
+ Win32ResourceFile="$(Win32Resource)"
+ />
+
+ <ItemGroup>
+ <_CoreCompileResourceInputs Remove="@(_CoreCompileResourceInputs)" />
+ </ItemGroup>
+
+ </Target>
+
+ <Import Project="$(MSBuildBinPath)\Microsoft.Common.targets"/>
+
+</Project>
+
View
BIN  lib/bootstrap/2.0/fsc.exe 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/2.0/fsi.exe
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Build.dll 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Compiler.Interactive.Settings.dll
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Compiler.Server.Shared.dll
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Compiler.dll 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Core.dll 100644 → 100755
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Core.optdata
Binary file not shown
View
BIN  lib/bootstrap/4.0/FSharp.Core.sigdata
Binary file not shown
View
2  lib/bootstrap/4.0/Microsoft.FSharp.targets
@@ -191,4 +191,4 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Import Project="$(MSBuildBinPath)\Microsoft.Common.targets"/>
</Project>
-
+
View
BIN  lib/bootstrap/4.0/fsc.exe
Binary file not shown
View
BIN  lib/bootstrap/4.0/fsi.exe
Binary file not shown
View
60 src/fsharp/FSharp.Core/FSharp.Core.fsproj 100755 → 100644
@@ -12,6 +12,9 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<FSharpSourcesRoot>..\..</FSharpSourcesRoot>
+ <ProductVersion>10.0.0</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <UsePartialTypes>False</UsePartialTypes>
</PropertyGroup>
<Import Project="$(FSharpSourcesRoot)\FSharpSource.Settings.targets" />
<PropertyGroup>
@@ -31,12 +34,7 @@
<OtherFlags Condition=" '$(TargetFramework)'=='net20' or '$(TargetFramework)'=='mono20'">$(OtherFlags) --compiling-fslib-20:"$(SystemRoot)\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" </OtherFlags>
<OtherFlags Condition=" '$(TargetFramework)'=='net40' or '$(TargetFramework)'=='mono40'">$(OtherFlags) --compiling-fslib-40</OtherFlags>
</PropertyGroup>
-
-
<ItemGroup>
- <CustomAdditionalCompileInputs Include="$(FSharpSourcesRoot)\..\Proto\$(protoCLIDir)\bin\fsc-proto.exe">
- <Visible>false</Visible>
- </CustomAdditionalCompileInputs>
<EmbeddedResource Include="FSCore.resx">
<Link>FSCore.resx</Link>
</EmbeddedResource>
@@ -133,18 +131,6 @@
<Compile Include="event.fs">
<Link>event.fs</Link>
</Compile>
- <Compile Include="math/n.fsi">
- <Link>n.fsi</Link>
- </Compile>
- <Compile Include="math/n.fs">
- <Link>n.fs</Link>
- </Compile>
- <Compile Include="math/z.fsi">
- <Link>z.fsi</Link>
- </Compile>
- <Compile Include="math/z.fs">
- <Link>z.fs</Link>
- </Compile>
<Compile Include="..\..\utils\sformat.fsi">
<Link>sformat.fsi</Link>
</Compile>
@@ -176,31 +162,24 @@
<Link>control.fs</Link>
</Compile>
<Compile Include="Linq.fsi">
- <Visible>true</Visible>
<Link>Linq.fsi</Link>
</Compile>
<Compile Include="Linq.fs">
- <Visible>true</Visible>
<Link>Linq.fs</Link>
</Compile>
<Compile Include="MutableTuple.fs">
- <Visible>true</Visible>
<Link>MutableTuple.fs</Link>
</Compile>
<Compile Include="QueryExtensions.fs">
- <Visible>true</Visible>
<Link>QueryExtensions.fs</Link>
</Compile>
- <Compile Include="Query.fsi" >
- <Visible>true</Visible>
+ <Compile Include="Query.fsi">
<Link>Query.fsi</Link>
</Compile>
- <Compile Include="Query.fs" >
- <Visible>true</Visible>
+ <Compile Include="Query.fs">
<Link>Query.fs</Link>
</Compile>
- <Compile Include="SI.fs" >
- <Visible>true</Visible>
+ <Compile Include="SI.fs">
<Link>SI.fs</Link>
</Compile>
<Compile Include="fslib-extra-pervasives.fsi">
@@ -212,20 +191,29 @@
<Compile Include="..\..\assemblyinfo\assemblyinfo.FSharp.Core.dll.fs">
<Link>assemblyinfo.FSharp.Core.dll.fs</Link>
</Compile>
+ <CustomAdditionalCompileInputs Include="Proto\%24%28protoCLIDir%29\bin\fsc-proto.exe">
+ <Visible>False</Visible>
+ </CustomAdditionalCompileInputs>
+ <Compile Include="math\n.fsi">
+ <Link>n.fsi</Link>
+ </Compile>
+ <Compile Include="math\n.fs">
+ <Link>n.fs</Link>
+ </Compile>
+ <Compile Include="math\z.fsi">
+ <Link>z.fsi</Link>
+ </Compile>
+ <Compile Include="math\z.fs">
+ <Link>z.fs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Numerics" Condition="'$(TargetFramework)' == 'net40' or '$(TargetFramework)'=='mono40'" />
- <Reference Include="System.Net" Condition="'$(TargetFramework)' == 'sl5' OR
- '$(TargetFramework)' == 'sl5-compiler' OR
- '$(TargetFramework)' == 'XNA\5.0' OR
- '$(TargetFramework)' == 'sl3-wp' "/>
- <Reference Include="System.Observable" Condition="'$(TargetFramework)' == 'sl3-wp' "/>
- <Reference Include="System.Core" Condition="'$(TargetFramework)' == 'sl5' OR
- '$(TargetFramework)' == 'sl5-compiler' OR
- '$(TargetFramework)' == 'XNA\5.0' OR
- '$(TargetFramework)' == 'sl3-wp' "/>
+ <Reference Include="System.Net" Condition="'$(TargetFramework)' == 'sl5' OR &#xD;&#xA; '$(TargetFramework)' == 'sl5-compiler' OR &#xD;&#xA; '$(TargetFramework)' == 'XNA\5.0' OR &#xD;&#xA; '$(TargetFramework)' == 'sl3-wp' " />
+ <Reference Include="System.Observable" Condition="'$(TargetFramework)' == 'sl3-wp' " />
+ <Reference Include="System.Core" Condition="'$(TargetFramework)' == 'sl5' OR &#xD;&#xA; '$(TargetFramework)' == 'sl5-compiler' OR &#xD;&#xA; '$(TargetFramework)' == 'XNA\5.0' OR &#xD;&#xA; '$(TargetFramework)' == 'sl3-wp' " />
</ItemGroup>
<!-- References -->
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" />
View
23 src/fsharp/FSharp.Core/Makefile.in
@@ -10,13 +10,21 @@ FSC=$(protodir)fsc-proto.exe
FLAGS_2_0 += \
$(FINAL_FLAGS) \
- --target:library \
- --compiling-fslib
+ --compiling-fslib \
+ --nowarn:75,1204 \
+ --target:library \
+ --define:FX_NO_BIGINT \
+ --compiling-fslib-20:$(monolibdir)mscorlib.dll \
+ --extraoptimizationloops:1
FLAGS_4_0 += \
$(FINAL_FLAGS) \
- $(FLAGS_2_0) \
- --compiling-fslib-mscorlib40:$(monolibdir)mscorlib.dll
+ --compiling-fslib \
+ --nowarn:75,1204 \
+ --target:library \
+ --define:FX_NO_BIGINT_CULTURE_PARSE \
+ --compiling-fslib-40 \
+ --extraoptimizationloops:1
DEFINES += \
--define:RUNTIME
@@ -67,6 +75,13 @@ sources = \
nativeptr.fs \
control.fsi \
control.fs \
+ Linq.fsi \
+ Linq.fs \
+ MutableTuple.fs \
+ QueryExtensions.fs \
+ Query.fsi \
+ Query.fs \
+ SI.fs \
fslib-extra-pervasives.fsi \
fslib-extra-pervasives.fs \
../../assemblyinfo/assemblyinfo.FSharp.Core.dll.fs
View
822 src/fsharp/FSharp.Core/math/z.fs
@@ -1,409 +1,413 @@
-//----------------------------------------------------------------------------
-// Copyright (c) 2002-2012 Microsoft Corporation.
-//
-// This source code is subject to terms and conditions of the Apache License, Version 2.0. A
-// copy of the license can be found in the License.html file at the root of this distribution.
-// By using this source code in any fashion, you are agreeing to be bound
-// by the terms of the Apache License, Version 2.0.
-//
-// You must not remove this notice, or any other, from this software.
-//----------------------------------------------------------------------------
-
-#nowarn "44" // This construct is deprecated. This function is for use by compiled F# code and should not be used directly
-namespace System.Numerics
-
-#if FX_NO_BIGINT
- open Microsoft.FSharp.Collections
- open Microsoft.FSharp.Core
- open Microsoft.FSharp.Core.Operators
- open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
- open Microsoft.FSharp.Primitives.Basics
- open Microsoft.FSharp.Math
- open System
- open System.Globalization
-
-
- // INVARIANT: signInt = 1 or -1
- // value(z) = signInt * v
- // NOTE: 0 has two repns (+1,0) or (-1,0).
- [<Struct>]
- [<CustomEquality; CustomComparison>]
- [<StructuredFormatDisplay("{StructuredDisplayString}I")>]
- type BigInteger(signInt:int, v : BigNat) =
-
- static let smallLim = 4096
- static let smallPosTab = Array.init smallLim BigNatModule.ofInt32
- static let one = BigInteger(1)
- static let zero = BigInteger(0)
-
- static member internal nat n =
- if BigNatModule.isSmall n && BigNatModule.getSmall n < smallLim
- then smallPosTab.[BigNatModule.getSmall n]
- else n
- static member internal create (s,n) = BigInteger(s,BigInteger.nat n)
- static member internal posn n = BigInteger(1,BigInteger.nat n)
- static member internal negn n = BigInteger(-1,BigInteger.nat n)
-
-
- member x.Sign = if x.IsZero then 0 else signInt
- member x.SignInt = signInt
- member internal x.V = v
-
- static member op_Equality (x:BigInteger, y:BigInteger) =
- //System.Console.WriteLine("x = {0}",box x)
- //System.Console.WriteLine("y = {0}",box y)
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigNatModule.equal x.V y.V // +1.xv = +1.yv iff xv = yv
- | -1, -1 -> BigNatModule.equal x.V y.V // -1.xv = -1.yv iff xv = yv
- | 1,-1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // 1.xv = -1.yv iff xv=0 and yv=0
- | -1, 1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // -1.xv = 1.yv iff xv=0 and yv=0
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member op_Inequality (x:BigInteger, y:BigInteger) = not (BigInteger.op_Equality(x,y)) // CA2226: OperatorsShouldHaveSymmetricalOverloads
-
- static member op_LessThan (x:BigInteger, y:BigInteger) =
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigNatModule.lt x.V y.V // 1.xv < 1.yv iff xv < yv
- | -1,-1 -> BigNatModule.lt y.V x.V // -1.xv < -1.yv iff yv < xv
- | 1,-1 -> false // 1.xv < -1.yv iff 0 <= 1.xv < -1.yv <= 0 iff false
- | -1, 1 -> not (BigNatModule.isZero x.V) || not (BigNatModule.isZero y.V)
- // -1.xv < 1.yv
- // (a) xv=0 and yv=0, then false
- // (b) xv<>0, -1.xv < 0 <= 1.yv, so true
- // (c) yv<>0, -1.xv <= 0 < 1.yv, so true
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member op_GreaterThan (x:BigInteger, y:BigInteger) = // Follow lt by +/- symmetry
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigNatModule.gt x.V y.V
- | -1,-1 -> BigNatModule.gt y.V x.V
- | 1,-1 -> not (BigNatModule.isZero x.V) || not (BigNatModule.isZero y.V)
- | -1, 1 -> false
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member internal compare(n,nn) = if BigInteger.op_LessThan(n,nn) then -1 elif BigInteger.op_Equality(n,nn) then 0 else 1
- static member internal hash (z:BigInteger) = z.SignInt + BigNatModule.hash(z.V)
-
- override x.ToString() =
- match x.SignInt with
- | 1 -> BigNatModule.toString x.V // positive
- | -1 ->
- if BigNatModule.isZero x.V
- then "0" // not negative infact, but zero.
- else "-" + BigNatModule.toString x.V // negative
- | _ -> invalidOp "signs should be +/- 1"
-
- member x.StructuredDisplayString = x.ToString()
-
- interface System.IComparable with
- member this.CompareTo(obj:obj) =
- match obj with
- | :? BigInteger as that -> BigInteger.compare(this,that)
- | _ -> invalidArg "obj" "the objects are not comparable"
-
- override this.Equals(obj) =
- match obj with
- | :? BigInteger as that -> BigInteger.op_Equality(this, that)
- | _ -> false
-
- override x.GetHashCode() = BigInteger.hash(x)
-
-
- new (n:int) =
- if n>=0
- then BigInteger (1,BigInteger.nat(BigNatModule.ofInt32 n))
- elif (n = System.Int32.MinValue)
- then BigInteger(-1,BigInteger.nat(BigNatModule.ofInt64 (-(int64 n))))
- else BigInteger(-1,BigInteger.nat(BigNatModule.ofInt32 (-n)))
-
-
- new (n:int64) =
- if n>=0L
- then BigInteger(1,BigInteger.nat (BigNatModule.ofInt64 n))
- elif (n = System.Int64.MinValue)
- then BigInteger(-1,BigInteger.nat (BigNatModule.add (BigNatModule.ofInt64 System.Int64.MaxValue) BigNatModule.one) )
- else BigInteger(-1,BigInteger.nat (BigNatModule.ofInt64 (-n)))
-
- static member One = one
- static member Zero = zero
- static member (~-) (z:BigInteger) = BigInteger.create(-1 * z.SignInt,z.V)
- static member Scale(k,z:BigInteger) =
- if k<0
- then BigInteger.create(-z.SignInt, (BigNatModule.scale (-k) z.V)) // k.zsign.zv = -zsign.(-k.zv)
- else BigInteger.create(z.SignInt, (BigNatModule.scale k z.V)) // k.zsign.zv = zsign.k.zv
-
- // Result: 1.nx - 1.ny (integer subtraction)
- static member internal subnn (nx,ny) =
- if BigNatModule.gte nx ny
- then BigInteger.posn (BigNatModule.sub nx ny) // nx >= ny, result +ve, +1.(nx - ny)
- else BigInteger.negn (BigNatModule.sub ny nx) // nx < ny, result -ve, -1.(ny - nx)
-
- static member internal addnn (nx,ny) =
- BigInteger.posn (BigNatModule.add nx ny) // Compute "nx + ny" to be integer
-
- member x.IsZero = BigNatModule.isZero x.V // signx.xv = 0 iff xv=0, since signx is +1,-1
- member x.IsOne = (x.SignInt = 1) && BigNatModule.isOne x.V // signx.xv = 1 iff signx = +1 and xv = 1
- static member (+) (x:BigInteger,y:BigInteger) =
- if y.IsZero then x else
- if x.IsZero then y else
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigInteger.addnn(x.V,y.V) // 1.xv + 1.yv = (xv + yv)
- | -1,-1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv + -1.yv = -(xv + yv)
- | 1,-1 -> BigInteger.subnn (x.V,y.V) // 1.xv + -1.yv = (xv - yv)
- | -1, 1 -> BigInteger.subnn(y.V,x.V) // -1.xv + 1.yv = (yv - xv)
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member (-) (x:BigInteger,y:BigInteger) =
- if y.IsZero then x else
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigInteger.subnn(x.V,y.V) // 1.xv - 1.yv = (xv - yv)
- | -1,-1 -> BigInteger.subnn(y.V,x.V) // -1.xv - -1.yv = (yv - xv)
- | 1,-1 -> BigInteger.addnn(x.V,y.V) // 1.xv - -1.yv = (xv + yv)
- | -1, 1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv - 1.yv = -(xv + yv)
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member ( * ) (x:BigInteger,y:BigInteger) =
- if x.IsZero then x
- elif y.IsZero then y
- elif x.IsOne then y
- elif y.IsOne then x
- else
- let m = (BigNatModule.mul x.V y.V)
- BigInteger.create (x.SignInt * y.SignInt,m) // xsign.xv * ysign.yv = (xsign.ysign).(xv.yv)
-
- static member DivRem (x:BigInteger,y:BigInteger,rem:BigInteger byref) =
- let d,r = BigNatModule.divmod x.V y.V
- // HAVE: |x| = d.|y| + r and 0 <= r < |y|
- // HAVE: xv = d.yv + r and 0 <= r < yv
- match x.SignInt,y.SignInt with
- | 1, 1 -> rem <- BigInteger.posn r ; BigInteger.posn d // 1.xv = 1.d.( 1.yv) + ( 1.r)
- | -1,-1 -> rem <- BigInteger.negn r ; BigInteger.posn d // -1.xv = 1.d.(-1.yv) + (-1.r)
- | 1,-1 -> rem <- BigInteger.posn r ; BigInteger.negn d // 1.xv = -1.d.(-1.yv) + ( 1.r)
- | -1, 1 -> rem <- BigInteger.negn r ; BigInteger.negn d // -1.xv = -1.d.( 1.yv) + (-1.r)
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member (/) (x:BigInteger,y:BigInteger) =
- let mutable rem = new BigInteger(0)
- BigInteger.DivRem(x,y,&rem)
- static member (%) (x:BigInteger,y:BigInteger) =
- let mutable rem = new BigInteger(0)
- BigInteger.DivRem(x,y,&rem) |> ignore ; rem
- static member GreatestCommonDivisor (x:BigInteger,y:BigInteger) = BigInteger.posn (BigNatModule.hcf x.V y.V) // hcf (xsign.xv,ysign.yv) = hcf (xv,yv)
-
- member x.IsNegative = x.SignInt = -1 && not (x.IsZero) // signx.xv < 0 iff signx = -1 and xv<>0
- member x.IsPositive = x.SignInt = 1 && not (x.IsZero) // signx.xv > 0 iff signx = +1 and xv<>0
- static member Abs (x:BigInteger) = if x.SignInt = -1 then -x else x
-
- static member op_LessThanOrEqual (x:BigInteger,y:BigInteger) =
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigNatModule.lte x.V y.V // 1.xv <= 1.yv iff xv <= yv
- | -1,-1 -> BigNatModule.lte y.V x.V // -1.xv <= -1.yv iff yv <= xv
- | 1,-1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // 1.xv <= -1.yv,
- // (a) if xv=0 and yv=0 then true
- // (b) otherwise false, only meet at zero.
-
- | -1, 1 -> true // -1.xv <= 1.yv, true
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member op_GreaterThanOrEqual (x:BigInteger,y:BigInteger) = // Follow lte by +/- symmetry
- match x.SignInt,y.SignInt with
- | 1, 1 -> BigNatModule.gte x.V y.V
- | -1,-1 -> BigNatModule.gte y.V x.V
- | 1,-1 -> true
- | -1, 1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V
- | _ -> invalidArg "x" "signs should be +/- 1"
-
-
- static member Pow (x:BigInteger,y:int32) =
- if y < 0 then invalidArg "y" (SR.GetString(SR.inputMustBeNonNegative))
- let yval = BigInteger(y)
- BigInteger.create ((if BigNatModule.isZero (BigNatModule.rem yval.V BigNatModule.two) then 1 else x.SignInt), BigNatModule.pow x.V yval.V)
-
- static member op_Explicit (x:BigInteger) =
- let u = BigNatModule.toUInt32 x.V
- if u <= uint32 System.Int32.MaxValue then
- // Handle range [-MaxValue,MaxValue]
- x.SignInt * int32 u
- elif x.SignInt = -1 && u = uint32 (System.Int32.MaxValue + 1) then
- //assert(System.Int32.MinValue = 0 - System.Int32.MaxValue - 1)
- // Handle MinValue = -(MaxValue+1) special case not covered by the above
- System.Int32.MinValue
- else
- raise (System.OverflowException())
-
- static member op_Explicit (x:BigInteger) =
- let u = BigNatModule.toUInt64 x.V
- if u <= uint64 System.Int64.MaxValue then
- (* Handle range [-MaxValue,MaxValue] *)
- int64 x.SignInt * int64 u
- elif x.SignInt = -1 && u = uint64 (System.Int64.MaxValue + 1L) then
- //assert(System.Int64.MinValue = 0 - System.Int64.MaxValue - 1L)
- (* Handle MinValue = -(MaxValue+1) special case not covered by the above *)
- System.Int64.MinValue
- else
- raise (System.OverflowException())
-
- static member op_Explicit (x:BigInteger) =
- match x.SignInt with
- | 1 -> BigNatModule.toFloat x.V // float (1.xv) = float (xv)
- | -1 -> - (BigNatModule.toFloat x.V) // float (-1.xv) = - float (xv)
- | _ -> invalidArg "x" "signs should be +/- 1"
-
- static member Parse(text:string) =
- let len = text.Length
- if len = 0 then raise (new System.FormatException("The value could not be parsed"))
- if text.[0..0] = "-" then
- BigInteger.negn (BigNatModule.ofString text.[1..len-1])
- else
- BigInteger.posn (BigNatModule.ofString text)
-
- member internal x.IsSmall = BigNatModule.isSmall (x.V)
- static member Factorial (x:BigInteger) =
- if x.IsNegative then invalidArg "x" (SR.GetString(SR.inputMustBeNonNegative))
- if x.IsPositive then BigInteger.posn (BigNatModule.factorial x.V)
- else BigInteger.One
-
- static member ( ~+ )(n1:BigInteger) = n1
-
- static member FromInt64(x:int64) = new BigInteger(x)
- static member FromInt32(x:int32) = new BigInteger(x)
-#endif
-
-namespace Microsoft.FSharp.Core
-
-
- type bigint = System.Numerics.BigInteger
-
- open System
- open System.Diagnostics.CodeAnalysis
- open System.Globalization
- open Microsoft.FSharp.Core.Operators
- open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
- open System.Numerics
-
-#if FX_NO_BIGINT
- // FxCop suppressions
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Addition(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Division(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_GreaterThan(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_GreaterThanOrEqual(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_LessThan(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_LessThanOrEqual(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Modulus(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Multiply(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Subtraction(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_UnaryNegation(System.Numerics.BigInteger)")>]
- [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_UnaryPlus(System.Numerics.BigInteger)")>]
- do()
-#endif
-
- [<AutoOpen>]
- module NumericLiterals =
-
- module NumericLiteralI =
-
- let tab64 = new System.Collections.Generic.Dictionary<int64,obj>()
- let tabParse = new System.Collections.Generic.Dictionary<string,obj>()
-
- let FromInt64Dynamic (x64:int64) : obj =
- lock tab64 (fun () ->
- let mutable res = Unchecked.defaultof<_>
- let ok = tab64.TryGetValue(x64,&res)
- if ok then res else
- res <- BigInteger(x64)
- tab64.[x64] <- res
- res)
-
- let inline get32 (x32:int32) = FromInt64Dynamic (int64 x32)
-
- let inline isOX s = not (System.String.IsNullOrEmpty(s)) && s.Length > 2 && s.[0] = '0' && s.[1] = 'x'
-
- let FromZero () : 'T =
- (get32 0 :?> 'T)
- when 'T : BigInteger = BigInteger.Zero
-
- let FromOne () : 'T =
- (get32 1 :?> 'T)
- when 'T : BigInteger = BigInteger.One
-
- let FromInt32 (i:int32): 'T =
- (get32 i :?> 'T)
- when 'T : BigInteger = new BigInteger(i)
-
- let FromInt64 (i:int64): 'T =
- (FromInt64Dynamic i :?> 'T)
- when 'T : BigInteger = new BigInteger(i)
-
- let getParse s =
- lock tabParse (fun () ->
- let mutable res = Unchecked.defaultof<_>
- let ok = tabParse.TryGetValue(s,&res)
- if ok then
- res
- else
-#if FSHARP_CORE_PORTABLE
- // SL5 (and therefore Portable Profile47) does not have Parse, so make our own simple implementation
- let parse(s : string) =
- // ws* sign? digits+ ws*
- let mutable i = 0
- // leading whitespace
- while i < s.Length && System.Char.IsWhiteSpace(s.[i]) do
- i <- i + 1
- if i = s.Length then
- raise <| new System.ArgumentException()
- // optional sign
- let mutable isNegative = false
- if s.[i] = '+' then
- i <- i + 1
- elif s.[i] = '-' then
- isNegative <- true
- i <- i + 1
- if i = s.Length then
- raise <| new System.ArgumentException()
- // digits
- let startDigits = i
- while i < s.Length && System.Char.IsDigit(s.[i]) do
- i <- i + 1
- let endDigits = i
- let len = endDigits - startDigits
- if len = 0 then
- raise <| new System.ArgumentException()
- // trailing whitespace
- while i < s.Length && System.Char.IsWhiteSpace(s.[i]) do
- i <- i + 1
- if i <> s.Length then
- raise <| new System.ArgumentException()
- // text is now valid, parse it
- let mutable r = new System.Numerics.BigInteger(int(s.[startDigits]) - int('0'))
- let ten = new System.Numerics.BigInteger(10)
- for j in startDigits+1 .. endDigits-1 do
- r <- r * ten
- r <- r + new System.Numerics.BigInteger(int(s.[j]) - int('0'))
- if isNegative then
- r <- new System.Numerics.BigInteger(0) - r
- r
- let v = parse s
-#else
- let v =
-#if FX_NO_BIGINT
- BigInteger.Parse s
-#else
- if isOX s then
- BigInteger.Parse (s.[2..],NumberStyles.AllowHexSpecifier,CultureInfo.InvariantCulture)
- else
- BigInteger.Parse (s,NumberStyles.AllowLeadingSign,CultureInfo.InvariantCulture)
-#endif
-#endif
- res <- v
- tabParse.[s] <- res
- res)
-
- let FromStringDynamic (s:string) : obj =
- getParse s
-
- let FromString (s:string) : 'T =
- (FromStringDynamic s :?> 'T)
- when 'T : BigInteger = getParse s
-
-
-
+//----------------------------------------------------------------------------
+// Copyright (c) 2002-2012 Microsoft Corporation.
+//
+// This source code is subject to terms and conditions of the Apache License, Version 2.0. A
+// copy of the license can be found in the License.html file at the root of this distribution.
+// By using this source code in any fashion, you are agreeing to be bound
+// by the terms of the Apache License, Version 2.0.
+//
+// You must not remove this notice, or any other, from this software.
+//----------------------------------------------------------------------------
+
+#nowarn "44" // This construct is deprecated. This function is for use by compiled F# code and should not be used directly
+namespace System.Numerics
+
+#if FX_NO_BIGINT
+ open Microsoft.FSharp.Collections
+ open Microsoft.FSharp.Core
+ open Microsoft.FSharp.Core.Operators
+ open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
+ open Microsoft.FSharp.Primitives.Basics
+ open Microsoft.FSharp.Math
+ open System
+ open System.Globalization
+
+
+ // INVARIANT: signInt = 1 or -1
+ // value(z) = signInt * v
+ // NOTE: 0 has two repns (+1,0) or (-1,0).
+ [<Struct>]
+ [<CustomEquality; CustomComparison>]
+ [<StructuredFormatDisplay("{StructuredDisplayString}I")>]
+ type BigInteger(signInt:int, v : BigNat) =
+
+ static let smallLim = 4096
+ static let smallPosTab = Array.init smallLim BigNatModule.ofInt32
+ static let one = BigInteger(1)
+ static let zero = BigInteger(0)
+
+ static member internal nat n =
+ if BigNatModule.isSmall n && BigNatModule.getSmall n < smallLim
+ then smallPosTab.[BigNatModule.getSmall n]
+ else n
+ static member internal create (s,n) = BigInteger(s,BigInteger.nat n)
+ static member internal posn n = BigInteger(1,BigInteger.nat n)
+ static member internal negn n = BigInteger(-1,BigInteger.nat n)
+
+
+ member x.Sign = if x.IsZero then 0 else signInt
+ member x.SignInt = signInt
+ member internal x.V = v
+
+ static member op_Equality (x:BigInteger, y:BigInteger) =
+ //System.Console.WriteLine("x = {0}",box x)
+ //System.Console.WriteLine("y = {0}",box y)
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigNatModule.equal x.V y.V // +1.xv = +1.yv iff xv = yv
+ | -1, -1 -> BigNatModule.equal x.V y.V // -1.xv = -1.yv iff xv = yv
+ | 1,-1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // 1.xv = -1.yv iff xv=0 and yv=0
+ | -1, 1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // -1.xv = 1.yv iff xv=0 and yv=0
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member op_Inequality (x:BigInteger, y:BigInteger) = not (BigInteger.op_Equality(x,y)) // CA2226: OperatorsShouldHaveSymmetricalOverloads
+
+ static member op_LessThan (x:BigInteger, y:BigInteger) =
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigNatModule.lt x.V y.V // 1.xv < 1.yv iff xv < yv
+ | -1,-1 -> BigNatModule.lt y.V x.V // -1.xv < -1.yv iff yv < xv
+ | 1,-1 -> false // 1.xv < -1.yv iff 0 <= 1.xv < -1.yv <= 0 iff false
+ | -1, 1 -> not (BigNatModule.isZero x.V) || not (BigNatModule.isZero y.V)
+ // -1.xv < 1.yv
+ // (a) xv=0 and yv=0, then false
+ // (b) xv<>0, -1.xv < 0 <= 1.yv, so true
+ // (c) yv<>0, -1.xv <= 0 < 1.yv, so true
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member op_GreaterThan (x:BigInteger, y:BigInteger) = // Follow lt by +/- symmetry
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigNatModule.gt x.V y.V
+ | -1,-1 -> BigNatModule.gt y.V x.V
+ | 1,-1 -> not (BigNatModule.isZero x.V) || not (BigNatModule.isZero y.V)
+ | -1, 1 -> false
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member internal compare(n,nn) = if BigInteger.op_LessThan(n,nn) then -1 elif BigInteger.op_Equality(n,nn) then 0 else 1
+ static member internal hash (z:BigInteger) = z.SignInt + BigNatModule.hash(z.V)
+
+ override x.ToString() =
+ match x.SignInt with
+ | 1 -> BigNatModule.toString x.V // positive
+ | -1 ->
+ if BigNatModule.isZero x.V
+ then "0" // not negative infact, but zero.
+ else "-" + BigNatModule.toString x.V // negative
+ | _ -> invalidOp "signs should be +/- 1"
+
+ member x.StructuredDisplayString = x.ToString()
+
+ interface System.IComparable with
+ member this.CompareTo(obj:obj) =
+ match obj with
+ | :? BigInteger as that -> BigInteger.compare(this,that)
+ | _ -> invalidArg "obj" "the objects are not comparable"
+
+ override this.Equals(obj) =
+ match obj with
+ | :? BigInteger as that -> BigInteger.op_Equality(this, that)
+ | _ -> false
+
+ override x.GetHashCode() = BigInteger.hash(x)
+
+
+ new (n:int) =
+ if n>=0
+ then BigInteger (1,BigInteger.nat(BigNatModule.ofInt32 n))
+ elif (n = System.Int32.MinValue)
+ then BigInteger(-1,BigInteger.nat(BigNatModule.ofInt64 (-(int64 n))))
+ else BigInteger(-1,BigInteger.nat(BigNatModule.ofInt32 (-n)))
+
+
+ new (n:int64) =
+ if n>=0L
+ then BigInteger(1,BigInteger.nat (BigNatModule.ofInt64 n))
+ elif (n = System.Int64.MinValue)
+ then BigInteger(-1,BigInteger.nat (BigNatModule.add (BigNatModule.ofInt64 System.Int64.MaxValue) BigNatModule.one) )
+ else BigInteger(-1,BigInteger.nat (BigNatModule.ofInt64 (-n)))
+
+ static member One = one
+ static member Zero = zero
+ static member (~-) (z:BigInteger) = BigInteger.create(-1 * z.SignInt,z.V)
+ static member Scale(k,z:BigInteger) =
+ if k<0
+ then BigInteger.create(-z.SignInt, (BigNatModule.scale (-k) z.V)) // k.zsign.zv = -zsign.(-k.zv)
+ else BigInteger.create(z.SignInt, (BigNatModule.scale k z.V)) // k.zsign.zv = zsign.k.zv
+
+ // Result: 1.nx - 1.ny (integer subtraction)
+ static member internal subnn (nx,ny) =
+ if BigNatModule.gte nx ny
+ then BigInteger.posn (BigNatModule.sub nx ny) // nx >= ny, result +ve, +1.(nx - ny)
+ else BigInteger.negn (BigNatModule.sub ny nx) // nx < ny, result -ve, -1.(ny - nx)
+
+ static member internal addnn (nx,ny) =
+ BigInteger.posn (BigNatModule.add nx ny) // Compute "nx + ny" to be integer
+
+ member x.IsZero = BigNatModule.isZero x.V // signx.xv = 0 iff xv=0, since signx is +1,-1
+ member x.IsOne = (x.SignInt = 1) && BigNatModule.isOne x.V // signx.xv = 1 iff signx = +1 and xv = 1
+ static member (+) (x:BigInteger,y:BigInteger) =
+ if y.IsZero then x else
+ if x.IsZero then y else
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigInteger.addnn(x.V,y.V) // 1.xv + 1.yv = (xv + yv)
+ | -1,-1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv + -1.yv = -(xv + yv)
+ | 1,-1 -> BigInteger.subnn (x.V,y.V) // 1.xv + -1.yv = (xv - yv)
+ | -1, 1 -> BigInteger.subnn(y.V,x.V) // -1.xv + 1.yv = (yv - xv)
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member (-) (x:BigInteger,y:BigInteger) =
+ if y.IsZero then x else
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigInteger.subnn(x.V,y.V) // 1.xv - 1.yv = (xv - yv)
+ | -1,-1 -> BigInteger.subnn(y.V,x.V) // -1.xv - -1.yv = (yv - xv)
+ | 1,-1 -> BigInteger.addnn(x.V,y.V) // 1.xv - -1.yv = (xv + yv)
+ | -1, 1 -> -(BigInteger.addnn(x.V,y.V)) // -1.xv - 1.yv = -(xv + yv)
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member ( * ) (x:BigInteger,y:BigInteger) =
+ if x.IsZero then x
+ elif y.IsZero then y
+ elif x.IsOne then y
+ elif y.IsOne then x
+ else
+ let m = (BigNatModule.mul x.V y.V)
+ BigInteger.create (x.SignInt * y.SignInt,m) // xsign.xv * ysign.yv = (xsign.ysign).(xv.yv)
+
+ static member DivRem (x:BigInteger,y:BigInteger,rem:BigInteger byref) =
+ let d,r = BigNatModule.divmod x.V y.V
+ // HAVE: |x| = d.|y| + r and 0 <= r < |y|
+ // HAVE: xv = d.yv + r and 0 <= r < yv
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> rem <- BigInteger.posn r ; BigInteger.posn d // 1.xv = 1.d.( 1.yv) + ( 1.r)
+ | -1,-1 -> rem <- BigInteger.negn r ; BigInteger.posn d // -1.xv = 1.d.(-1.yv) + (-1.r)
+ | 1,-1 -> rem <- BigInteger.posn r ; BigInteger.negn d // 1.xv = -1.d.(-1.yv) + ( 1.r)
+ | -1, 1 -> rem <- BigInteger.negn r ; BigInteger.negn d // -1.xv = -1.d.( 1.yv) + (-1.r)
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member (/) (x:BigInteger,y:BigInteger) =
+ let mutable rem = new BigInteger(0)
+ BigInteger.DivRem(x,y,&rem)
+ static member (%) (x:BigInteger,y:BigInteger) =
+ let mutable rem = new BigInteger(0)
+ BigInteger.DivRem(x,y,&rem) |> ignore ; rem
+ static member GreatestCommonDivisor (x:BigInteger,y:BigInteger) = BigInteger.posn (BigNatModule.hcf x.V y.V) // hcf (xsign.xv,ysign.yv) = hcf (xv,yv)
+
+ member x.IsNegative = x.SignInt = -1 && not (x.IsZero) // signx.xv < 0 iff signx = -1 and xv<>0
+ member x.IsPositive = x.SignInt = 1 && not (x.IsZero) // signx.xv > 0 iff signx = +1 and xv<>0
+ static member Abs (x:BigInteger) = if x.SignInt = -1 then -x else x
+
+ static member op_LessThanOrEqual (x:BigInteger,y:BigInteger) =
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigNatModule.lte x.V y.V // 1.xv <= 1.yv iff xv <= yv
+ | -1,-1 -> BigNatModule.lte y.V x.V // -1.xv <= -1.yv iff yv <= xv
+ | 1,-1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V // 1.xv <= -1.yv,
+ // (a) if xv=0 and yv=0 then true
+ // (b) otherwise false, only meet at zero.
+
+ | -1, 1 -> true // -1.xv <= 1.yv, true
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member op_GreaterThanOrEqual (x:BigInteger,y:BigInteger) = // Follow lte by +/- symmetry
+ match x.SignInt,y.SignInt with
+ | 1, 1 -> BigNatModule.gte x.V y.V
+ | -1,-1 -> BigNatModule.gte y.V x.V
+ | 1,-1 -> true
+ | -1, 1 -> BigNatModule.isZero x.V && BigNatModule.isZero y.V
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+
+ static member Pow (x:BigInteger,y:int32) =
+ if y < 0 then invalidArg "y" (SR.GetString(SR.inputMustBeNonNegative))
+ let yval = BigInteger(y)
+ BigInteger.create ((if BigNatModule.isZero (BigNatModule.rem yval.V BigNatModule.two) then 1 else x.SignInt), BigNatModule.pow x.V yval.V)
+
+ static member op_Explicit (x:BigInteger) =
+ let u = BigNatModule.toUInt32 x.V
+ if u <= uint32 System.Int32.MaxValue then
+ // Handle range [-MaxValue,MaxValue]
+ x.SignInt * int32 u
+ elif x.SignInt = -1 && u = uint32 (System.Int32.MaxValue + 1) then
+ //assert(System.Int32.MinValue = 0 - System.Int32.MaxValue - 1)
+ // Handle MinValue = -(MaxValue+1) special case not covered by the above
+ System.Int32.MinValue
+ else
+ raise (System.OverflowException())
+
+ static member op_Explicit (x:BigInteger) =
+ let u = BigNatModule.toUInt64 x.V
+ if u <= uint64 System.Int64.MaxValue then
+ (* Handle range [-MaxValue,MaxValue] *)
+ int64 x.SignInt * int64 u
+ elif x.SignInt = -1 && u = uint64 (System.Int64.MaxValue + 1L) then
+ //assert(System.Int64.MinValue = 0 - System.Int64.MaxValue - 1L)
+ (* Handle MinValue = -(MaxValue+1) special case not covered by the above *)
+ System.Int64.MinValue
+ else
+ raise (System.OverflowException())
+
+ static member op_Explicit (x:BigInteger) =
+ match x.SignInt with
+ | 1 -> BigNatModule.toFloat x.V // float (1.xv) = float (xv)
+ | -1 -> - (BigNatModule.toFloat x.V) // float (-1.xv) = - float (xv)
+ | _ -> invalidArg "x" "signs should be +/- 1"
+
+ static member Parse(text:string) =
+ let len = text.Length
+ if len = 0 then raise (new System.FormatException("The value could not be parsed"))
+ if text.[0..0] = "-" then
+ BigInteger.negn (BigNatModule.ofString text.[1..len-1])
+ else
+ BigInteger.posn (BigNatModule.ofString text)
+
+ member internal x.IsSmall = BigNatModule.isSmall (x.V)
+ static member Factorial (x:BigInteger) =
+ if x.IsNegative then invalidArg "x" (SR.GetString(SR.inputMustBeNonNegative))
+ if x.IsPositive then BigInteger.posn (BigNatModule.factorial x.V)
+ else BigInteger.One
+
+ static member ( ~+ )(n1:BigInteger) = n1
+
+ static member FromInt64(x:int64) = new BigInteger(x)
+ static member FromInt32(x:int32) = new BigInteger(x)
+#endif
+
+namespace Microsoft.FSharp.Core
+
+
+ type bigint = System.Numerics.BigInteger
+
+ open System
+ open System.Diagnostics.CodeAnalysis
+ open System.Globalization
+ open Microsoft.FSharp.Core.Operators
+ open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators
+ open System.Numerics
+
+#if FX_NO_BIGINT
+ // FxCop suppressions
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Addition(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Division(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_GreaterThan(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_GreaterThanOrEqual(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_LessThan(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_LessThanOrEqual(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Modulus(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Multiply(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_Subtraction(System.Numerics.BigInteger,System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_UnaryNegation(System.Numerics.BigInteger)")>]
+ [<assembly: SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Scope="member", Target="System.Numerics.BigInteger.#op_UnaryPlus(System.Numerics.BigInteger)")>]
+ do()
+#endif
+
+ [<AutoOpen>]
+ module NumericLiterals =
+
+ module NumericLiteralI =
+
+ let tab64 = new System.Collections.Generic.Dictionary<int64,obj>()
+ let tabParse = new System.Collections.Generic.Dictionary<string,obj>()
+
+ let FromInt64Dynamic (x64:int64) : obj =
+ lock tab64 (fun () ->
+ let mutable res = Unchecked.defaultof<_>
+ let ok = tab64.TryGetValue(x64,&res)
+ if ok then res else
+ res <- BigInteger(x64)
+ tab64.[x64] <- res
+ res)
+
+ let inline get32 (x32:int32) = FromInt64Dynamic (int64 x32)
+
+ let inline isOX s = not (System.String.IsNullOrEmpty(s)) && s.Length > 2 && s.[0] = '0' && s.[1] = 'x'
+
+ let FromZero () : 'T =
+ (get32 0 :?> 'T)
+ when 'T : BigInteger = BigInteger.Zero
+
+ let FromOne () : 'T =
+ (get32 1 :?> 'T)
+ when 'T : BigInteger = BigInteger.One
+
+ let FromInt32 (i:int32): 'T =
+ (get32 i :?> 'T)
+ when 'T : BigInteger = new BigInteger(i)
+
+ let FromInt64 (i:int64): 'T =
+ (FromInt64Dynamic i :?> 'T)
+ when 'T : BigInteger = new BigInteger(i)
+
+ let getParse s =
+ lock tabParse (fun () ->
+ let mutable res = Unchecked.defaultof<_>
+ let ok = tabParse.TryGetValue(s,&res)
+ if ok then
+ res
+ else
+#if FSHARP_CORE_PORTABLE
+ // SL5 (and therefore Portable Profile47) does not have Parse, so make our own simple implementation
+ let parse(s : string) =
+ // ws* sign? digits+ ws*
+ let mutable i = 0
+ // leading whitespace
+ while i < s.Length && System.Char.IsWhiteSpace(s.[i]) do
+ i <- i + 1
+ if i = s.Length then
+ raise <| new System.ArgumentException()
+ // optional sign
+ let mutable isNegative = false
+ if s.[i] = '+' then
+ i <- i + 1
+ elif s.[i] = '-' then
+ isNegative <- true
+ i <- i + 1
+ if i = s.Length then
+ raise <| new System.ArgumentException()
+ // digits
+ let startDigits = i
+ while i < s.Length && System.Char.IsDigit(s.[i]) do
+ i <- i + 1
+ let endDigits = i
+ let len = endDigits - startDigits
+ if len = 0 then
+ raise <| new System.ArgumentException()
+ // trailing whitespace
+ while i < s.Length && System.Char.IsWhiteSpace(s.[i]) do
+ i <- i + 1
+ if i <> s.Length then
+ raise <| new System.ArgumentException()
+ // text is now valid, parse it
+ let mutable r = new System.Numerics.BigInteger(int(s.[startDigits]) - int('0'))
+ let ten = new System.Numerics.BigInteger(10)
+ for j in startDigits+1 .. endDigits-1 do
+ r <- r * ten
+ r <- r + new System.Numerics.BigInteger(int(s.[j]) - int('0'))
+ if isNegative then
+ r <- new System.Numerics.BigInteger(0) - r
+ r
+ let v = parse s
+#else
+ let v =
+#if FX_NO_BIGINT
+ BigInteger.Parse s
+#else
+#if FX_NO_BIGINT_CULTURE_PARSE
+ BigInteger.Parse s
+#else
+ if isOX s then
+ BigInteger.Parse (s.[2..],NumberStyles.AllowHexSpecifier,CultureInfo.InvariantCulture)
+ else
+ BigInteger.Parse (s,NumberStyles.AllowLeadingSign,CultureInfo.InvariantCulture)
+#endif
+#endif
+#endif
+ res <- v
+ tabParse.[s] <- res
+ res)
+
+ let FromStringDynamic (s:string) : obj =
+ getParse s
+
+ let FromString (s:string) : 'T =
+ (FromStringDynamic s :?> 'T)
+ when 'T : BigInteger = getParse s
+
+
+
View
11 src/fsharp/Fsc-proto/Makefile.in
@@ -23,17 +23,6 @@ REFERENCES += \
-r:$(monolibdir)System.Windows.Forms.dll
sources = \
- $(tmpdir)FSCstrings.fs \
- ../../utils/filename.fsi \
- ../../utils/filename.fs \
- ../fsc.fs \
../fscmain.fs
-RESOURCES = \
- $(tmpdir)FSCstrings.resources
-
-$(tmpdir)FSCstrings.resources: $(srcdir)../FSCstrings.txt
- mono --debug $(FSSRGEN) $< $(@:.resources=.fs) $(@:.resources=.resx)
- resgen $(@:.resources=.resx) $@
-
include $(topdir)/src/fsharp/targets.make
Please sign in to comment.
Something went wrong with that request. Please try again.