public override Number Subtract (Number x, Number y) { if (x.data.Length < 6 || y.data.Length < 6) return ToElement (base.Subtract (x, y)); int cmp = x.CompareTo (y); if (cmp == 0) return PADDED_ZERO; uint[] pz = new uint[6], px = x.data, py = y.data; if (cmp > 0) { uint tmp, carry; tmp = py[0]; carry = ((pz[0] = px[0] - tmp) > ~tmp ? 1U : 0U); tmp = py[1] + carry; carry = (tmp < carry | (pz[1] = px[1] - tmp) > ~tmp ? 1U : 0U); tmp = py[2] + carry; carry = (tmp < carry | (pz[2] = px[2] - tmp) > ~tmp ? 1U : 0U); tmp = py[3] + carry; carry = (tmp < carry | (pz[3] = px[3] - tmp) > ~tmp ? 1U : 0U); tmp = py[4] + carry; carry = (tmp < carry | (pz[4] = px[4] - tmp) > ~tmp ? 1U : 0U); pz[5] = px[5] - py[5] - carry; } else { long tmp; int carry = 0; pz[0] = (uint)(tmp = ((long)px[0]) + ((long)P1) - ((long)py[0]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0); pz[1] = (uint)(tmp = ((long)px[1]) + ((long)P2) - ((long)py[1]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0); pz[2] = (uint)(tmp = ((long)px[2]) + ((long)P3) - ((long)py[2]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0); pz[3] = (uint)(tmp = ((long)px[3]) + ((long)P4) - ((long)py[3]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0); pz[4] = (uint)(tmp = ((long)px[4]) + ((long)P5) - ((long)py[4]) - carry); carry = (tmp < 0 ? 1 : tmp > 0xFFFFFFFF ? -1 : 0); pz[5] = (uint)(tmp = ((long)px[5]) + ((long)P6) - ((long)py[5]) - carry); } return new Number (pz); }
public Ending(Number number, Person person, Tense tense, Voice voice) { _number = number; _person = person; _tense = tense; _voice = voice; }
private string GetInfix(Person person, Number number) { switch (_infixType) { case InfixType.B: if (person == Person.First && number == Number.Singular) { return "bo"; } if (person == Person.Second && number == Number.Singular) { return "be"; } if (person == Person.Third && number == Number.Plural) { return "bu"; } return "bi"; case InfixType.A: if (person == Person.First && number == Number.Singular) { return "a"; } return "e"; default: throw new NotImplementedException(); } }
/// <summary> /// Declares a variable if there is a declaration and deletes unnessesary stuff /// </summary> /// <param name="listE"> stream of tokens </param> /// <returns> true if we need to launch the function again </returns> public static bool DeclareVariable(List<Element> listE) { if (listE.Count > 2) // it can be a declaration only if the list has more than 2 elements { if (listE[0].Type == C.Number && listE[1].Type == C.Control) // if it is a number { string name = listE[0].GetNumber().Name; if (name != "" && listE[1].ToString() == "=") // if it is a variable { listE.RemoveRange(0, 2); Number num = new Number(Parse(listE).Value.ToString()); num.Name = name; Variable.Add(num); return false; } } } int index = listE.FindIndex(delegate(Element e) { if (e.ToString() == "=") return true; return false; }); if (index != -1) { listE.RemoveRange(0, index + 1); return true; } return false; }
public override BetResult GetResult(Number number) { if (number.Color == NumberColor.None) return BetResult.PARTIAL; else return number.Color == Color ? BetResult.WIN : BetResult.LOSE; }
private PersonalPronoun(Case personalPronounCase, Number number, Person person, string name) { _case = personalPronounCase; _number = number; _person = person; _name = name; }
EvaluationCallback GetNumberCallback(Number number) { EvaluationCallback callback; if (m_numbercallbacks.TryGetValue(number, out callback) == true) return callback; DynamicMethod method = new DynamicMethod(String.Empty, typeof(Number), new Type[] { typeof(Object) }, typeof(TreeCompiler)); ILGenerator generator = method.GetILGenerator(); switch (number.NumberType) { case NumberType.Int: generator.Emit(OpCodes.Ldc_I4, number.IntValue); generator.Emit(OpCodes.Newobj, typeof(Number).GetConstructor(new Type[] { typeof(Int32) })); break; case NumberType.Float: generator.Emit(OpCodes.Ldc_R4, number.FloatValue); generator.Emit(OpCodes.Newobj, typeof(Number).GetConstructor(new Type[] { typeof(Single) })); break; default: generator.Emit(OpCodes.Ldloc, generator.DeclareLocal(typeof(Number)).LocalIndex); break; } generator.Emit(OpCodes.Ret); callback = (EvaluationCallback)method.CreateDelegate(typeof(EvaluationCallback)); m_numbercallbacks[number] = callback; return callback; }
public LiteralNumber(Number numberValue) { if (numberValue == null) throw new ArgumentException("NumberValue is null!"); NumberValue = numberValue; }
private static bool HexNumberToInt64(ref Number.NumberBuffer number, ref long value) { ulong num = 0uL; bool result = Number.HexNumberToUInt64(ref number, ref num); value = (long)num; return result; }
public override Number Add (Number x, Number y) { if (x.data.Length < 6 || y.data.Length < 6) return ToElement (base.Add (x, y)); ulong sum; uint[] pz = new uint[7], px = x.data, py = y.data; uint tmp, carry; pz[0] = (uint)(sum = ((ulong)px[0]) + ((ulong)py[0])); sum >>= 32; pz[1] = (uint)(sum += ((ulong)px[1]) + ((ulong)py[1])); sum >>= 32; pz[2] = (uint)(sum += ((ulong)px[2]) + ((ulong)py[2])); sum >>= 32; pz[3] = (uint)(sum += ((ulong)px[3]) + ((ulong)py[3])); sum >>= 32; pz[4] = (uint)(sum += ((ulong)px[4]) + ((ulong)py[4])); sum >>= 32; pz[5] = (uint)(sum += ((ulong)px[5]) + ((ulong)py[5])); sum >>= 32; pz[6] = (uint)sum; if (pz[6] != 0 || CompareTo (pz[0], pz[1], pz[2], pz[3], pz[4], pz[5]) <= 0) { carry = ((pz[0] -= P1) > ~P1 ? 1U : 0U); tmp = P2 + carry; carry = (tmp < carry | (pz[1] -= tmp) > ~tmp ? 1U : 0U); tmp = P3 + carry; carry = (tmp < carry | (pz[2] -= tmp) > ~tmp ? 1U : 0U); tmp = P4 + carry; carry = (tmp < carry | (pz[3] -= tmp) > ~tmp ? 1U : 0U); tmp = P5 + carry; carry = (tmp < carry | (pz[4] -= tmp) > ~tmp ? 1U : 0U); pz[5] -= P6 + carry; } pz[6] = 0; return new Number (pz); }
public Barrett (Number mod) : base (mod) { int len = mod.length << 1; constant = new Number (len + 1); constant.data[len] = 1; constant = constant / mod; }
public NumberWrapper(Number value) { if (value != null) { Value = value.Value; } }
internal ECKeyPair (Number d, ECPoint Q, ECDomainParameters domain, ECDomainNames domainName) { _d = d; _Q = Q; _domain = domain; _domainName = domainName; }
/// <summary> /// Given an input feature, a feature space and its associated labels, and a positive integer 'k', /// Determines the 'k' nearest neighbor label for the input feature. The 'k' value corresponds /// to the number of nearest neighbors to use in the voting process. /// /// <remarks> /// "When I have this grid of data points, and I provide one additional example row, find the 'k' number /// of rows that are most similar, count up the number of occurrences of each label for each row (1 to 'k'), /// and choose the label with the highest occurrence." /// </remarks> /// <see href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm" /> /// </summary> /// <param name="distanceType">The type of equation to use when measuring the distance between each data point</param> /// <param name="input">The matrix row to input; must have the same number of columns as the feature space</param> /// <param name="featureSpace">The feature space matrix; everything we know</param> /// <param name="labels">The results for each feature space row; what we call each collection of data points</param> /// <param name="k">The number of nearest neighbors to include in the voting; the label with the most occurrences in 'k' neighbors wins</param> /// <returns></returns> public static string Classify(DistanceType distanceType, Number[] input, Matrix featureSpace, IList<string> labels, int k) { if (labels.Count() != featureSpace.Rows) { throw new ArgumentException("The number of labels must match the number of rows of data in the feature space", "labels"); } var distances = CalculateDistances(distanceType, featureSpace, input); var nearestNeighbors = distances.OrderByDescending(d => d.Value).Take(k); var votes = new Dictionary<string, int>(k); foreach (var label in nearestNeighbors.Select(neighbor => labels[neighbor.Key])) { if (votes.ContainsKey(label)) { votes[label]++; } else { votes.Add(label, 1); } } var nearest = votes.OrderByDescending(v => v.Value).First().Key; return nearest; }
static void Main(string[] args) { //constant var one = new Number<Bit>(); one.Construct(); //a few additions var two = one.Add(one); var three = one.Add(two); var six = three.Add(three); var ten = one.Add(three.Add(six)); //proof that any regular object can be used, not just one which represents a bit var anotherOne = new Number<Number<Bit>>(); anotherOne.Construct(); var four = anotherOne.Add(anotherOne.Add(anotherOne.Add(anotherOne))); //display results Console.WriteLine("one: {0}: '{1}'", one.Evaluate(), one); Console.WriteLine("two: {0}: '{1}'", two.Evaluate(), two); Console.WriteLine("three: {0}: '{1}'", three.Evaluate(), three); Console.WriteLine("four: {0}: '{1}'", four.Evaluate(), four); Console.WriteLine("six: {0}: '{1}'", six.Evaluate(), six); Console.WriteLine("ten: {0}: '{1}'", ten.Evaluate(), ten); Console.ReadKey(); }
//所有数字按钮(含小数点) private void NumberButton_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; if (IsEqualPress) { FirstNumber.NumString.Clear(); FirstNumber.NumString.Append("0"); FirstNumber.Num = 0; IsEqualPress = false; } if (IsFirstNum) { FirstNumber = JudgeInput(FirstNumber, button); ShowResultTextBlock.Text = FirstNumber.NumString.ToString(); if (ShowResultTextBlock.Text.Length > 8) ShowResultTextBlock.FontSize = 90 * 8 / ShowResultTextBlock.Text.Length; else ShowResultTextBlock.FontSize = 90; } else { SecondNumber = JudgeInput(SecondNumber, button); ShowResultTextBlock.Text = SecondNumber.NumString.ToString(); if (ShowResultTextBlock.Text.Length > 8) ShowResultTextBlock.FontSize = 90 * 8 / ShowResultTextBlock.Text.Length; else ShowResultTextBlock.FontSize = 90; } }
private static bool HexNumberToInt32(ref Number.NumberBuffer number, ref int value) { uint num = 0u; bool result = Number.HexNumberToUInt32(ref number, ref num); value = (int)num; return result; }
/// <summary> /// Creates a new instance of the AbsoluteNumber class /// </summary> /// <param name="nbr">The number that should be inside the absolute number</param> /// <exception cref="ArgumentNullException">Thrown if the number is null</exception> public AbsoluteNumber(Number nbr) { if(nbr == null) throw new ArgumentNullException(nameof(nbr),"The number can't be null"); InnerValue = nbr; }
public HslColor(Number hue, Number saturation, Number lightness, Number alpha) { Hue = (hue.ToNumber()/360d)%1d; Saturation = saturation.Normalize(100d)/100d; Lightness = lightness.Normalize(100d)/100d; Alpha = alpha.Normalize(); }
public ECGroup (Number a, Number b, Number mod, IFiniteField field) { _a = a; _b = b; _mod = mod; _field = field; _a_is_minus3 = (mod.CompareTo (a + Number.Three) == 0); }
public Calculator() { InitializeComponent(); FirstNumber = new Number(); SecondNumber = new Number(); IsFirstNum = true; IsEqualPress = false; }
public void DeleteOverride(Case nounCase, Number number) { if (!Overrides.ContainsKey(nounCase) || !Overrides[nounCase].ContainsKey(number)) { return; } Overrides[nounCase].Remove(number); }
public void Write(Number value) { if (status != BufferStatus.AwaitingWrite) { throw new InvalidOperationException("Buffer was not awaiting write."); } bufferedValue = value; status = BufferStatus.AwaitingRead; }
private string GetEnding(Person person, Number number) { if (!ENDINGS.ContainsKey(_endings)) { throw new NotSupportedException(string.Format("unrecognised endings : {0}", _endings)); } return ENDINGS[_endings].Ending(person, number); }
public void DoesNotBreakOnDifferentLocale(string locale) { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(locale); var number = new Number(1234.5); var css = number.ToCss(); Assert.AreEqual("1234.5", css); }
public override Number multiple(Number otherNumber) { if (otherNumber.precedence() > precedence()) return otherNumber.multiple(this); double other = getOther(otherNumber); return new RadianNumber(modulateRadians(value + other)); }
public ECPoint (ECGroup group, Number x, Number y, Number z) { _group = group; _field = group.FiniteField; _x = x; _y = y; _z = z; }
public byte[] PerformKeyAgreement (byte[] otherPublicKey, int offset, int length) { Number otherPub = new Number (otherPublicKey, offset, length, false); Number sharedKey = new Classical (_p).Pow (otherPub, _private); byte[] buf = new byte[KeySizeValue >> 3]; sharedKey.CopyToBigEndian (buf, 0, buf.Length); return buf; }
public override Number absoluteDifference(Number otherNumber) { if (otherNumber.precedence() > precedence()) return otherNumber.absoluteDifference(this); double other = getOther(otherNumber); return new RadianNumber(modulateRadians(Math.Abs(value - other))); }
public string Get(Case nounCase, Number number) { if (Overrides.ContainsKey(nounCase) && Overrides[nounCase].ContainsKey(number)) { return Overrides[nounCase][number]; } return GetRegular(nounCase, number); }
public String ToString(String format) { Contract.Ensures(Contract.Result <String>() != null); return(Number.FormatInt32(m_value, format, NumberFormatInfo.CurrentInfo)); }
public String ToString(String format, IFormatProvider provider) { Contract.Ensures(Contract.Result <String>() != null); return(Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider))); }
public static int Parse(String s) { return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo)); }
public static int Parse(ReadOnlySpan <char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null) { NumberFormatInfo.ValidateParseStyleInteger(style); return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider))); }
public string ToString(string?format, IFormatProvider?provider) { return(Number.FormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider))); }
public string ToString(string format) { return(Number.FormatInt32(m_value, format, null)); }
public String ToString(IFormatProvider provider) { return(Number.FormatInt32(m_value, null, NumberFormatInfo.GetInstance(provider))); }
public static bool TryParse(String s, out Int32 result) { return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result)); }
public static int Parse(String s, NumberStyles style, IFormatProvider provider) { NumberFormatInfo.ValidateParseStyleInteger(style); return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider))); }
public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result) { NumberFormatInfo.ValidateParseStyleInteger(style); return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result)); }
public string ToString(string?format, IFormatProvider?provider) { return(Number.FormatInt32(m_value, 0x000000FF, format, provider)); }
public override String ToString() { Contract.Ensures(Contract.Result <String>() != null); return(Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo)); }
// Parses an integer from a String in the given style. If // a NumberFormatInfo isn't specified, the current culture's // NumberFormatInfo is assumed. // /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse3"]/*' /> public static int Parse(String s, NumberStyles style, IFormatProvider provider) { NumberFormatInfo info = NumberFormatInfo.GetInstance(provider); NumberFormatInfo.ValidateParseStyle(style); return Number.ParseInt32(s, style, info); }
// Parses an integer from a String in the given style. If // a NumberFormatInfo isn't specified, the current culture's // NumberFormatInfo is assumed. // /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse2"]/*' /> public static int Parse(String s, IFormatProvider provider) { NumberFormatInfo info = NumberFormatInfo.GetInstance(provider); return Number.ParseInt32(s, NumberStyles.Integer, info); }
public override String ToString() { return(Number.FormatInt32(m_value, null, NumberFormatInfo.CurrentInfo)); }
public static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, IFormatProvider provider, out int result) { NumberFormatInfo.ValidateParseStyleInteger(style); return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result, out _)); }
// Parses a double from a String in the given style. If // a NumberFormatInfo isn't specified, the current culture's // NumberFormatInfo is assumed. // // This method will not throw an OverflowException, but will return // PositiveInfinity or NegativeInfinity for a number that is too // large or too small. public static double Parse(ReadOnlySpan <char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider?provider = null) { NumberFormatInfo.ValidateParseStyleFloatingPoint(style); return(Number.ParseDouble(s, style, NumberFormatInfo.GetInstance(provider))); }
public override string ToString() { return(Number.FormatInt32(m_value, null, null)); }
public static int Parse(String s, IFormatProvider provider) { return(Number.ParseInt32(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider))); }
public static bool TryParse(ReadOnlySpan <char> s, out int result) { return(Number.TryParseInt32(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result, out _)); }
private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out double result) { return(Number.TryParseDouble(s, style, info, out result)); }
public string ToString(string?format) { return(Number.FormatDouble(m_value, format, NumberFormatInfo.CurrentInfo)); }
public bool TryFormat(Span <char> destination, out int charsWritten, ReadOnlySpan <char> format = default, IFormatProvider?provider = null) { return(Number.TryFormatDouble(m_value, format, NumberFormatInfo.GetInstance(provider), destination, out charsWritten)); }
public string ToString(string format, IFormatProvider provider) { return(Number.FormatInt32(m_value, format, provider)); }
public static int Parse(String s, NumberStyles style) { NumberFormatInfo.ValidateParseStyleInteger(style); return(Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo)); }
public bool TryFormat(Span <char> destination, out int charsWritten, ReadOnlySpan <char> format = default, IFormatProvider provider = null) { return(Number.TryFormatInt32(m_value, format, provider, destination, out charsWritten)); }
public static Boolean TryParse(String s, out Int64 result) { return(Number.TryParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result)); }
public string ToString(IFormatProvider provider) { return(Number.FormatInt32(m_value, null, provider)); }
/// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.ToString2"]/*' /> public String ToString(String format, IFormatProvider provider) { return Number.FormatInt32(m_value, format, NumberFormatInfo.GetInstance(provider)); }
// Provides a string representation of a byte. public override string ToString() { return(Number.Int32ToDecStr(m_value)); }