📄 mathslib.pas
字号:
unit MathsLib;
{Copyright 2005,2008 Gary Darby, www.DelphiForFun.org
This program may be used or modified for any non-commercial purpose
so long as this original notice remains in place.
All other rights are reserved
}
{Assortment of math related functions and procedure in various states}
{Revision Copyright 2006, Charles Doumar, January 2006
Added:
Tprimes.BSPrime ... Binary search function to find index of prime in prime table.
Tprimes.MaxPrimeInTable ... Returns Max Prime in prime table.
Tprimes.GetNthPrime ... Returns Nth prime in table (returns -1 if not in table).
Optimized:
Tprimes.IsPrime ... Optimized for values greater than MaxPrimeInTable squared.
Tprimes.NextPrime ... Speed up lookup of values within table range, added large value support
Tprime.PrevPrime ... Speed up lookup of values within table range, added large value support
Tprime.GetFactors ... Now returns factors for numbers greater than MaxPrimeInTable Squared
}
interface
uses Classes, SysUtils, Windows, Dialogs, UBigIntsV2;
type
intset = set of byte;
TPoint64=record
x,y:int64;
end;
function GetNextPandigital(size: integer; var Digits: array of integer): boolean;
function IsPolygonal(T: int64; var rank: array of integer): boolean;
function GeneratePentagon(n: integer): integer;
function IsPentagon(p: integer): boolean;
function isSquare(const N: int64): boolean;
function isCube(const N: int64): boolean;
function isPalindrome(n: int64): boolean;
function GetEulerPhi(n: int64): int64;
function IntPower(a, b: int64): int64; overload;
function IntPower(a:extended; b: int64): extended; overload;
function gcd2(a, b: int64): int64;
function GCDMany(A: array of integer): integer;
function LCMMany(A: array of integer): integer;
procedure ContinuedFraction(A: array of int64; const wholepart: integer;
var numerator, denominator: int64);
function Factorial(n: int64): int64;
function digitcount(n:int64):integer;
function convertfloattofractionstring( N:extended; maxdenom:integer;multipleof:boolean):string;
function convertStringToDecimal(s:string; var n:extended):Boolean; {string may include fractions}
function InttoBinaryStr(nn: integer): string;
{Latitude Longitude Routines}
function StrtoAngle(const s:string; var angle:extended):boolean;
function AngleToStr(angle:extended):string;
function deg2rad(deg:extended):extended;
function rad2deg(rad:extended):extended;
function GetLongToMercProjection(const long:extended):extended;
function GetLatToMercProjection(const Lat:Extended):Extended;
function GetMercProjectionToLong(const ProjLong:extended):extended;
function GetMercProjectionToLat(const ProjLat:extended):extended;
type
{*********** TPrimes Class *******}
TPrimes = class(TObject)
protected
function BSPrime(const n: int64; var index: integer): boolean;
public
Prime: array of int64; {Array of primes - 0th entry is not used}
nbrprimes, nbrfactors, nbrcanonicalfactors, nbrdivisors: integer;
Factors: array of int64; {array of factors - 0th entry is not used}
CanonicalFactors: array of TPoint64;
Divisors: array of int64;
function GetNextPrime(n: int64): int64;
function GetPrevPrime(n: int64): int64;
function IsPrime(n: int64): boolean;
procedure GetFactors(const n: int64); {get all prime factors}
function MaxPrimeInTable: int64;
function GetNthPrime(const n: integer): int64;
procedure GetCanonicalFactors(const n: int64); {get ccanonical prime factors}
procedure GetDivisors(const n: int64); {get all divisors}
function Getnbrdivisors(n: int64): integer;
function radical(n:int64):int64; {product of unique prime factors}
constructor Create;
destructor Destroy; override;
end;
const deg=chr(176); {'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -