private bool IsCabinet(Stream cabStream, out short id, out int cabFolderCount, out int fileCount) { int streamHandle = StreamHandles.AllocHandle(cabStream); try { Erf.Clear(); NativeMethods.FDI.CABINFO fdici; bool isCabinet = 0 != NativeMethods.FDI.IsCabinet(fdiHandle, streamHandle, out fdici); if (Erf.Error) { if (((NativeMethods.FDI.ERROR)Erf.Oper) == NativeMethods.FDI.ERROR.UNKNOWN_CABINET_VERSION) { isCabinet = false; } else { throw new CabException( Erf.Oper, Erf.Type, CabException.GetErrorMessage(Erf.Oper, Erf.Type, true)); } } id = fdici.setID; cabFolderCount = fdici.cFolders; fileCount = fdici.cFiles; return(isCabinet); } finally { StreamHandles.FreeHandle(streamHandle); } }
/// <inheritdoc/> public new double inverseCumulativeProbability(double p) { if (p < 0.0 || p > 1.0) { throw new OutOfRangeException <Double>(p, 0, 1); } return(mean + standardDeviation * SQRT2 * Erf.erfInv(2 * p - 1)); }
public IList <ArchiveFileInfo> GetFileInfo( IUnpackStreamContext streamContext, Predicate <string> fileFilter) { if (streamContext == null) { throw new ArgumentNullException("streamContext"); } lock (this) { _context = streamContext; _filter = fileFilter; NextCabinetName = string.Empty; _fileList = new List <ArchiveFileInfo>(); var tmpSuppress = SuppressProgressEvents; SuppressProgressEvents = true; try { for (short cabNumber = 0; NextCabinetName != null; cabNumber++) { Erf.Clear(); CabNumbers[NextCabinetName] = cabNumber; NativeMethods.FDI.Copy( _fdiHandle, NextCabinetName, string.Empty, 0, CabListNotify, IntPtr.Zero, IntPtr.Zero); CheckError(true); } var tmpFileList = _fileList; _fileList = null; return(tmpFileList.AsReadOnly()); } finally { SuppressProgressEvents = tmpSuppress; if (CabStream != null) { _context.CloseArchiveReadStream( CurrentArchiveNumber, CurrentArchiveName, CabStream); CabStream = null; } _context = null; } } }
/// <inheritdoc/> /// <remarks> /// If <c>x</c> is more than 40 standard deviations from the mean, 0 or 1 /// is returned, as in these cases the actual value is within /// <c>Double.MinValue</c> of 0 or 1. /// </remarks> public override double cumulativeProbability(double x) { double dev = x - mean; if (FastMath.abs(dev) > 40 * standardDeviation) { return(dev < 0 ? 0.0d : 1.0d); } return(0.5 * (1 + Erf.erf(dev / (standardDeviation * SQRT2)))); }
private void AddFile( string name, Stream stream, FileAttributes attributes, DateTime lastWriteTime, bool execute, CompressionLevel compLevel) { FileStream = stream; _fileAttributes = attributes & (FileAttributes.Archive | FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System); _fileLastWriteTime = lastWriteTime; CurrentFileName = name; var tcomp = GetCompressionType(compLevel); var namePtr = IntPtr.Zero; try { var nameEncoding = Encoding.ASCII; if (Encoding.UTF8.GetByteCount(name) > name.Length) { nameEncoding = Encoding.UTF8; _fileAttributes |= FileAttributes.Normal; // _A_NAME_IS_UTF } var nameBytes = nameEncoding.GetBytes(name); namePtr = Marshal.AllocHGlobal(nameBytes.Length + 1); Marshal.Copy(nameBytes, 0, namePtr, nameBytes.Length); Marshal.WriteByte(namePtr, nameBytes.Length, 0); Erf.Clear(); NativeMethods.FCI.AddFile( _fciHandle, string.Empty, namePtr, execute, _fciGetNextCabinet, _fciCreateStatus, _fciGetOpenInfo, tcomp); } finally { if (namePtr != IntPtr.Zero) { Marshal.FreeHGlobal(namePtr); } } CheckError(false); FileStream = null; CurrentFileName = null; }
private void CreateFci(long maxArchiveSize) { var ccab = new NativeMethods.FCI.CCAB(); if (maxArchiveSize > 0 && maxArchiveSize < ccab.cb) { ccab.cb = Math.Max( NativeMethods.FCI.MIN_DISK, (int)maxArchiveSize); } var maxFolderSizeOption = _context.GetOption( "maxFolderSize", null); if (maxFolderSizeOption != null) { var maxFolderSize = Convert.ToInt64( maxFolderSizeOption, CultureInfo.InvariantCulture); if (maxFolderSize > 0 && maxFolderSize < ccab.cbFolderThresh) { ccab.cbFolderThresh = (int)maxFolderSize; } } _maxCabBytes = ccab.cb; ccab.szCab = _context.GetArchiveName(0); if (ccab.szCab == null) { throw new FileNotFoundException("Cabinet name not provided by stream context."); } ccab.setID = (short)new Random().Next( Int16.MinValue, Int16.MaxValue + 1); CabNumbers[ccab.szCab] = 0; CurrentArchiveName = ccab.szCab; TotalArchives = 1; CabStream = null; Erf.Clear(); _fciHandle = NativeMethods.FCI.Create( ErfHandle.AddrOfPinnedObject(), _fciFilePlacedHandler, _fciAllocMemHandler, _fciFreeMemHandler, _fciOpenStreamHandler, _fciReadStreamHandler, _fciWriteStreamHandler, _fciCloseStreamHandler, _fciSeekStreamHandler, _fciDeleteFileHandler, _fciGetTempFileHandler, ccab, IntPtr.Zero); CheckError(false); }
/// <inheritdoc/> public new double probability(double x0, double x1) { if (x0 > x1) { throw new NumberIsTooLargeException <Double, Double>(new LocalizedFormats("LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT"), x0, x1, true); } double denom = standardDeviation * SQRT2; double v0 = (x0 - mean) / denom; double v1 = (x1 - mean) / denom; return(0.5 * Erf.erf(v0, v1)); }
/// <summary> /// Creates a new, empty ERF file of the specified type. /// </summary> /// <param name="type">The type of the ERF</param> /// <param name="description">The ERF's description</param> /// <returns></returns> public static Erf New(ErfType type, string description) { // Create the ERF file and it's header. Erf erf = new Erf(); erf.header = new ErfHeader(type); // Create empty key/resource files since an empty ERF contains 0 files. erf.keys = new ErfKey[0]; erf.resources = new ErfResource[0]; // Create an ErfString for the description. erf.descriptions = new ErfString[1]; erf.descriptions[0] = new ErfString(description, type); // Setup the header to account for our description. erf.header.LanguageCount = 1; erf.header.LocalizedStringSize = erf.descriptions[0].SizeInStream; erf.header.OffsetToLocalizedString = Marshal.SizeOf(typeof(ErfHeader)); erf.header.OffsetToKeyList = erf.header.OffsetToLocalizedString + erf.header.LocalizedStringSize; return erf; }
/// <summary> /// Loads the specified ERF file, returning an instance to it. /// </summary> /// <param name="fileName">The name of the ERF file to load</param> /// <returns>An Erf object for the file</returns> public static Erf Load(string fileName) { // Open the erf file. Erf erf = new Erf(); using (FileStream reader = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { erf.fileInfo = new FileInfo(fileName); // Read the header from the ERF erf.header = new ErfHeader(reader); // Read the description(s) from the ERF reader.Seek(erf.header.OffsetToLocalizedString, SeekOrigin.Begin); erf.descriptions = ErfString.Deserialize(reader, erf.header.LanguageCount, erf.header.ErfType); // Read the key (file) list from the ERF. reader.Seek(erf.header.OffsetToKeyList, SeekOrigin.Begin); erf.keys = ErfKey.Deserialize(reader, erf.header.EntryCount, erf.header.Version); // Build the keys's hash table for fast access to files. foreach (ErfKey key in erf.keys) try { erf.keyHash.Add(key.FileName.ToLower(), key); } catch (ArgumentException) {} // Read the resource (file) list from the ERF. reader.Seek(erf.header.OffsetToResourceList, SeekOrigin.Begin); erf.resources = ErfResource.Deserialize(reader, erf.header.EntryCount); } return erf; }
private void FlushCabinet() { Erf.Clear(); NativeMethods.FCI.FlushCabinet(_fciHandle, false, _fciGetNextCabinet, _fciCreateStatus); CheckError(false); }
public void Unpack( IUnpackStreamContext streamContext, Predicate <string> fileFilter) { lock (this) { IList <ArchiveFileInfo> files = GetFileInfo(streamContext, fileFilter); ResetProgressData(); if (files != null) { totalFiles = files.Count; for (int i = 0; i < files.Count; i++) { totalFileBytes += files[i].Length; if (files[i].ArchiveNumber >= this.totalArchives) { int totalArchives = files[i].ArchiveNumber + 1; this.totalArchives = (short)totalArchives; } } } context = streamContext; fileList = null; NextCabinetName = String.Empty; folderId = -1; currentFileNumber = -1; try { for (short cabNumber = 0; NextCabinetName != null; cabNumber++) { Erf.Clear(); CabNumbers[NextCabinetName] = cabNumber; NativeMethods.FDI.Copy( fdiHandle, NextCabinetName, String.Empty, 0, CabExtractNotify, IntPtr.Zero, IntPtr.Zero); CheckError(true); } } finally { if (CabStream != null) { context.CloseArchiveReadStream( currentArchiveNumber, currentArchiveName, CabStream); CabStream = null; } if (FileStream != null) { context.CloseFileWriteStream(currentFileName, FileStream, FileAttributes.Normal, DateTime.Now); FileStream = null; } context = null; } } }
public BuiltInFunctions() { // Text Functions["len"] = new Len(); Functions["lower"] = new Lower(); Functions["upper"] = new Upper(); Functions["left"] = new Left(); Functions["right"] = new Right(); Functions["mid"] = new Mid(); Functions["replace"] = new Replace(); Functions["rept"] = new Rept(); Functions["substitute"] = new Substitute(); Functions["concatenate"] = new Concatenate(); Functions["concat"] = new Concat(); Functions["textjoin"] = new Textjoin(); Functions["char"] = new CharFunction(); Functions["exact"] = new Exact(); Functions["find"] = new Find(); Functions["fixed"] = new Fixed(); Functions["proper"] = new Proper(); Functions["search"] = new Search(); Functions["text"] = new Text.Text(); Functions["t"] = new T(); Functions["hyperlink"] = new Hyperlink(); Functions["value"] = new Value(CultureInfo.CurrentCulture); Functions["trim"] = new Trim(); Functions["clean"] = new Clean(); Functions["unicode"] = new Unicode(); Functions["unichar"] = new Unichar(); Functions["numbervalue"] = new NumberValue(); Functions["dollar"] = new Dollar(); // Numbers Functions["int"] = new CInt(); // Math Functions["aggregate"] = new Aggregate(); Functions["abs"] = new Abs(); Functions["asin"] = new Asin(); Functions["asinh"] = new Asinh(); Functions["acot"] = new Acot(); Functions["acoth"] = new Acoth(); Functions["cos"] = new Cos(); Functions["cot"] = new Cot(); Functions["coth"] = new Coth(); Functions["cosh"] = new Cosh(); Functions["csc"] = new Csc(); Functions["csch"] = new Csch(); Functions["power"] = new Power(); Functions["gcd"] = new Gcd(); Functions["lcm"] = new Lcm(); Functions["sec"] = new Sec(); Functions["sech"] = new SecH(); Functions["sign"] = new Sign(); Functions["sqrt"] = new Sqrt(); Functions["sqrtpi"] = new SqrtPi(); Functions["pi"] = new Pi(); Functions["product"] = new Product(); Functions["ceiling"] = new Ceiling(); Functions["ceiling.precise"] = new CeilingPrecise(); Functions["ceiling.math"] = new CeilingMath(); Functions["iso.ceiling"] = new IsoCeiling(); Functions["combin"] = new Combin(); Functions["combina"] = new Combina(); Functions["permut"] = new Permut(); Functions["permutationa"] = new Permutationa(); Functions["count"] = new Count(); Functions["counta"] = new CountA(); Functions["countblank"] = new CountBlank(); Functions["countif"] = new CountIf(); Functions["countifs"] = new CountIfs(); Functions["fact"] = new Fact(); Functions["factdouble"] = new FactDouble(); Functions["floor"] = new Floor(); Functions["floor.precise"] = new FloorPrecise(); Functions["floor.math"] = new FloorMath(); Functions["radians"] = new Radians(); Functions["roman"] = new Roman(); Functions["sin"] = new Sin(); Functions["sinh"] = new Sinh(); Functions["sum"] = new Sum(); Functions["sumif"] = new SumIf(); Functions["sumifs"] = new SumIfs(); Functions["sumproduct"] = new SumProduct(); Functions["sumsq"] = new Sumsq(); Functions["sumxmy2"] = new Sumxmy2(); Functions["sumx2my2"] = new SumX2mY2(); Functions["sumx2py2"] = new SumX2pY2(); Functions["seriessum"] = new Seriessum(); Functions["stdev"] = new Stdev(); Functions["stdeva"] = new Stdeva(); Functions["stdevp"] = new StdevP(); Functions["stdevpa"] = new Stdevpa(); Functions["stdev.s"] = new StdevDotS(); Functions["stdev.p"] = new StdevDotP(); Functions["subtotal"] = new Subtotal(); Functions["exp"] = new Exp(); Functions["log"] = new Log(); Functions["log10"] = new Log10(); Functions["ln"] = new Ln(); Functions["max"] = new Max(); Functions["maxa"] = new Maxa(); Functions["median"] = new Median(); Functions["min"] = new Min(); Functions["mina"] = new Mina(); Functions["mod"] = new Mod(); Functions["mode"] = new Mode(); Functions["mode.sngl"] = new ModeSngl(); Functions["mround"] = new Mround(); Functions["multinomial"] = new Multinomial(); Functions["average"] = new Average(); Functions["averagea"] = new AverageA(); Functions["averageif"] = new AverageIf(); Functions["averageifs"] = new AverageIfs(); Functions["round"] = new Round(); Functions["rounddown"] = new Rounddown(); Functions["roundup"] = new Roundup(); Functions["rand"] = new Rand(); Functions["randbetween"] = new RandBetween(); Functions["rank"] = new Rank(); Functions["rank.eq"] = new RankEq(); Functions["rank.avg"] = new RankAvg(); Functions["percentile"] = new Percentile(); Functions["percentile.inc"] = new PercentileInc(); Functions["percentile.exc"] = new PercentileExc(); Functions["quartile"] = new Quartile(); Functions["quartile.inc"] = new QuartileInc(); Functions["quartile.exc"] = new QuartileExc(); Functions["percentrank"] = new Percentrank(); Functions["percentrank.inc"] = new PercentrankInc(); Functions["percentrank.exc"] = new PercentrankExc(); Functions["quotient"] = new Quotient(); Functions["trunc"] = new Trunc(); Functions["tan"] = new Tan(); Functions["tanh"] = new Tanh(); Functions["atan"] = new Atan(); Functions["atan2"] = new Atan2(); Functions["atanh"] = new Atanh(); Functions["acos"] = new Acos(); Functions["acosh"] = new Acosh(); Functions["covar"] = new Covar(); Functions["covariance.p"] = new CovarianceP(); Functions["covariance.s"] = new CovarianceS(); Functions["var"] = new Var(); Functions["vara"] = new Vara(); Functions["var.s"] = new VarDotS(); Functions["varp"] = new VarP(); Functions["varpa"] = new Varpa(); Functions["var.p"] = new VarDotP(); Functions["large"] = new Large(); Functions["small"] = new Small(); Functions["degrees"] = new Degrees(); Functions["odd"] = new Odd(); Functions["even"] = new Even(); // Information Functions["isblank"] = new IsBlank(); Functions["isnumber"] = new IsNumber(); Functions["istext"] = new IsText(); Functions["isnontext"] = new IsNonText(); Functions["iserror"] = new IsError(); Functions["iserr"] = new IsErr(); Functions["error.type"] = new ErrorType(); Functions["iseven"] = new IsEven(); Functions["isodd"] = new IsOdd(); Functions["islogical"] = new IsLogical(); Functions["isna"] = new IsNa(); Functions["na"] = new Na(); Functions["n"] = new N(); Functions["type"] = new TypeFunction(); // Logical Functions["if"] = new If(); Functions["ifs"] = new Ifs(); Functions["maxifs"] = new MaxIfs(); Functions["minifs"] = new MinIfs(); Functions["iferror"] = new IfError(); Functions["ifna"] = new IfNa(); Functions["not"] = new Not(); Functions["and"] = new And(); Functions["or"] = new Or(); Functions["true"] = new True(); Functions["false"] = new False(); Functions["switch"] = new Switch(); Functions["xor"] = new Xor(); // Reference and lookup Functions["address"] = new Address(); Functions["hlookup"] = new HLookup(); Functions["vlookup"] = new VLookup(); Functions["lookup"] = new Lookup(); Functions["match"] = new Match(); Functions["row"] = new Row(); Functions["rows"] = new Rows(); Functions["column"] = new Column(); Functions["columns"] = new Columns(); Functions["choose"] = new Choose(); Functions["index"] = new RefAndLookup.Index(); Functions["indirect"] = new Indirect(); Functions["offset"] = new Offset(); // Date Functions["date"] = new Date(); Functions["datedif"] = new DateDif(); Functions["today"] = new Today(); Functions["now"] = new Now(); Functions["day"] = new Day(); Functions["month"] = new Month(); Functions["year"] = new Year(); Functions["time"] = new Time(); Functions["hour"] = new Hour(); Functions["minute"] = new Minute(); Functions["second"] = new Second(); Functions["weeknum"] = new Weeknum(); Functions["weekday"] = new Weekday(); Functions["days"] = new Days(); Functions["days360"] = new Days360(); Functions["yearfrac"] = new Yearfrac(); Functions["edate"] = new Edate(); Functions["eomonth"] = new Eomonth(); Functions["isoweeknum"] = new IsoWeekNum(); Functions["workday"] = new Workday(); Functions["workday.intl"] = new WorkdayIntl(); Functions["networkdays"] = new Networkdays(); Functions["networkdays.intl"] = new NetworkdaysIntl(); Functions["datevalue"] = new DateValue(); Functions["timevalue"] = new TimeValue(); // Database Functions["dget"] = new Dget(); Functions["dcount"] = new Dcount(); Functions["dcounta"] = new DcountA(); Functions["dmax"] = new Dmax(); Functions["dmin"] = new Dmin(); Functions["dsum"] = new Dsum(); Functions["daverage"] = new Daverage(); Functions["dvar"] = new Dvar(); Functions["dvarp"] = new Dvarp(); //Finance Functions["cumipmt"] = new Cumipmt(); Functions["cumprinc"] = new Cumprinc(); Functions["dollarde"] = new DollarDe(); Functions["dollarfr"] = new DollarFr(); Functions["ddb"] = new Ddb(); Functions["effect"] = new Effect(); Functions["fvschedule"] = new FvSchedule(); Functions["pduration"] = new Pduration(); Functions["rri"] = new Rri(); Functions["pmt"] = new Pmt(); Functions["ppmt"] = new Ppmt(); Functions["ipmt"] = new Ipmt(); Functions["ispmt"] = new IsPmt(); Functions["pv"] = new Pv(); Functions["fv"] = new Fv(); Functions["npv"] = new Npv(); Functions["rate"] = new Rate(); Functions["nper"] = new Nper(); Functions["nominal"] = new Nominal(); Functions["irr"] = new Irr(); Functions["mirr"] = new Mirr(); Functions["xirr"] = new Xirr(); Functions["sln"] = new Sln(); Functions["syd"] = new Syd(); Functions["xnpv"] = new Xnpv(); Functions["coupdays"] = new Coupdays(); Functions["coupdaysnc"] = new Coupdaysnc(); Functions["coupdaybs"] = new Coupdaybs(); Functions["coupnum"] = new Coupnum(); Functions["coupncd"] = new Coupncd(); Functions["couppcd"] = new Couppcd(); Functions["price"] = new Price(); Functions["yield"] = new Yield(); Functions["yieldmat"] = new Yieldmat(); Functions["duration"] = new Duration(); Functions["disc"] = new Disc(); //Engineering Functions["bitand"] = new BitAnd(); Functions["bitor"] = new BitOr(); Functions["bitxor"] = new BitXor(); Functions["bitlshift"] = new BitLshift(); Functions["bitrshift"] = new BitRshift(); Functions["convert"] = new ConvertFunction(); Functions["bin2dec"] = new Bin2Dec(); Functions["bin2hex"] = new Bin2Hex(); Functions["bin2oct"] = new Bin2Oct(); Functions["dec2bin"] = new Dec2Bin(); Functions["dec2hex"] = new Dec2Hex(); Functions["dec2oct"] = new Dec2Oct(); Functions["hex2bin"] = new Hex2Bin(); Functions["hex2dec"] = new Hex2Dec(); Functions["hex2oct"] = new Hex2Oct(); Functions["oct2bin"] = new Oct2Bin(); Functions["oct2dec"] = new Oct2Dec(); Functions["oct2hex"] = new Oct2Hex(); Functions["delta"] = new Delta(); Functions["erf"] = new Erf(); Functions["erf.precise"] = new ErfPrecise(); Functions["erfc"] = new Erfc(); Functions["erfc.precise"] = new ErfcPrecise(); Functions["besseli"] = new BesselI(); Functions["besselj"] = new BesselJ(); Functions["besselk"] = new BesselK(); Functions["bessely"] = new BesselY(); }
public double CalculatePercentileForValue(double value) { double alpha = (value - Mean) / (Deviation * Math.Sqrt(2)); return(0.5 * (1 + Erf.Compute(alpha))); }